Write a C++ program to create a Stack data structure. This Stack data structure is to store the integer values. Your program should display a menu of choices to operate the Stack data structure. See the sample menu below:
Stack Operations Menu
1. Add items
2. Delete items
3. Show the number of items
4. Show min and max items
5. Find an item
6. Print all items
Enter your choice:1
In Stack data structure, removing or adding an item is a LIFO(Last In First Out) process. It allows items to be added to the beginning of list and removed from the beginning of the list. In this solution to the exercise, we will build a Stack data structure to store the integer values. Each item of the Stack contains two parts--data and a link. The data part is to store the integer value and the link part is a pointer to store the address of its next item. The items in the Stack are chained together by links(or pointers). We also have two important links used to point to the first item(pfirst) and point to the last item(plast) that help us in most of operations on the Stack such as adding, deleting an item, traversing through the Stack, finding an item,etc.
To keep the solution simple, we divide the solution into different steps--Defining Stack item and function prototypes, Adding item, Counting all items, Removing item, showing minimum and maximum items, searching for an item, printing items on the screen, displaying a menu of choices and the last step is to combine the C code together. You can find their links in the left menu of the page.
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: