21.Problem statement
Write C++ program using STL for implementation of stack & queue using SLL
Program
#include<iostream>
#include<stack>
#include<stdlib.h>
using namespace std;
void display(stack<int>s)
{
cout<<"\nElement in stack are:- ";
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
}
int main()
{
stack<int>s;
int choice,t;
int x;
while(1)
{
cout<<"\n\n*********************************";
cout<<"\n STACK USING STL";
cout<<"\n*********************************";
cout<<"\n\n1.Push data";
cout<<"\n2.Pop data";
cout<<"\n3.Size of stack";
cout<<"\n4.First Element";
cout<<"\n5.Display Element in stack";
cout<<"\n6.Exit";
cout<<"\nEnter Your choice:- ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\nEnter Value to be insert:- ";
cin>>x;
s.push(x);
break;
case 2:
x=s.top();
s.pop();
cout<<"\nElement"<<x<<"Deleted from stack";
break;
case 3:
cout<<"\nSize of stack:- "<<s.size();
break;
case 4:
cout<<"\nTop Element of Stack:- "<<s.top();
break;
case 5:
display(s);
break;
case 6:
exit(1);
break;
}
}
return 0;
}
Write C++ program using STL for implementation of stack & queue using SLL
Program
#include<iostream>
#include<stack>
#include<stdlib.h>
using namespace std;
void display(stack<int>s)
{
cout<<"\nElement in stack are:- ";
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
}
int main()
{
stack<int>s;
int choice,t;
int x;
while(1)
{
cout<<"\n\n*********************************";
cout<<"\n STACK USING STL";
cout<<"\n*********************************";
cout<<"\n\n1.Push data";
cout<<"\n2.Pop data";
cout<<"\n3.Size of stack";
cout<<"\n4.First Element";
cout<<"\n5.Display Element in stack";
cout<<"\n6.Exit";
cout<<"\nEnter Your choice:- ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\nEnter Value to be insert:- ";
cin>>x;
s.push(x);
break;
case 2:
x=s.top();
s.pop();
cout<<"\nElement"<<x<<"Deleted from stack";
break;
case 3:
cout<<"\nSize of stack:- "<<s.size();
break;
case 4:
cout<<"\nTop Element of Stack:- "<<s.top();
break;
case 5:
display(s);
break;
case 6:
exit(1);
break;
}
}
return 0;
}
Comments
Post a Comment