C++ exercises and solutions: Stack item and operations


Stack item and operations

Step 1: Defining Stack item and operations
Each item of the Stack contains two parts. One part is to store the integer value and another part to store the address of its next item.
typedef struct ListNode{

int data; // the element data
struct ListNode *next; // next link

The operations associated with the Stack data structure can be outlined as the function prototypes shown below:

//Function prototypes
void Push (int);
ListElem *Pop();//Pop item from the stack
void printall();//print out all items on the screen
int countitem();//return the number of items in the stack
ListElem *find(int);//search for an item
ListElem *findmin();//show min item
ListElem *findmax();//show max item

//pfirst points the first item of the Stack and plast point to the last item
//of the Stack
ListElem *pfirst;
ListElem *plast;

You will find the definitions( code implementations) of the function prototypes in the next subsequent steps. See the left hand menu to find their links.


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.