Write c++ program using stl for implementation of stack & queue using STL.
OUTPUT OF THE PROGRAM |
#include<stack>
#include<queue>
using namespace std;
int main()
{
int item,item1,choice;
char con;
stack<int> st;
queue<int> q;
do
{
cout<<"\n1)insert an element\n2)delete an element\n3)size of element\n4)display top & front element\n5)Back element";
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"\nEnter the element: ";
cin>>item;
item1=item;
st.push(item);
q.push(item1);
break;
}
case 2:
{
item = st.top();
item1=q.front();
st.pop();
q.pop();
cout<<"\nElement "<<item<<" has been deleted";
cout<<"\nElement "<<item1<<" has been deleted";
break;
}
case 3:
{
cout<<"\nSize of the stack is "<<st.size();
cout<<"\nSize of the queue is "<<q.size();
break;
}
case 4:
{
cout<<"\nFront Element of the Queue: "<<q.front();
cout<<"\nTop element is "<<st.top();
break;
}
case 5:
{
cout<<"\nBack Element of the Queue: ";
cout<<q.back();
break;
}
}
cout<<"\nDo you want to continue(y/n): ";
cin>>con;
}
while(con=='y');
}
Tags
CODING