0% found this document useful (0 votes)
29 views1 page

Stack

This C++ program implements a stack using the STL stack container. It provides a menu for users to insert elements, delete elements, check the size, and view the top element of the stack. The main function contains a switch statement inside a while loop to process the user's menu selection and perform the corresponding stack operation.

Uploaded by

tapas_bayen9388
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Stack

This C++ program implements a stack using the STL stack container. It provides a menu for users to insert elements, delete elements, check the size, and view the top element of the stack. The main function contains a switch statement inside a while loop to process the user's menu selection and perform the corresponding stack operation.

Uploaded by

tapas_bayen9388
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Implementation:

#include <iostream>
#include <stack>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
stack<int> st;
int choice, item;
while (1)
{
cout<<"\n---------------------"<<endl;
cout<<"Stack Implementation in Stl"<<endl;
cout<<"\n---------------------"<<endl;
cout<<"1.Insert Element into the Stack"<<endl;
cout<<"2.Delete Element from the Stack"<<endl;
cout<<"3.Size of the Stack"<<endl;
cout<<"4.Top Element of the Stack"<<endl;
cout<<"5.Exit"<<endl;
cout<<"Enter your Choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter value to be inserted: ";
cin>>item;
st.push(item);
break;
case 2:
item = st.top();
st.pop();
cout<<"Element "<<item<<" Deleted"<<endl;
break;
case 3:
cout<<"Size of the Stack: ";
cout<<st.size()<<endl;
break;
case 4:
cout<<"Top Element of the Stack: ";
cout<<st.top()<<endl;
break;
case 5:
exit(1);
break;
default:
cout<<"Wrong Choice"<<endl;
}
}
return 0;
}

You might also like