Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- string stack[100], queue[100];
- int i,m=100,n=100,top=-1,countNum=0,countQue=0,bottom=-1,down=-1;
- /////STACK AREA
- void push(string val)
- {
- if(top>=n-1){
- cout<<"Stack overflow"<<endl;
- }
- else
- {
- top++;
- stack[top]=val;
- }
- }
- void pop()
- {
- if(top<=-1){
- cout<<"Stack undeflow"<<endl;
- }
- else
- {
- cout<<"The popped element is: "<<stack[top]<<endl;
- top--;
- }
- }
- void display()
- {
- if(top>=0){
- cout<<"The stack name is: "<<stack[top]<<endl;
- }
- else
- {
- cout<<"Stack is empty"<<endl;
- }
- }
- void count()
- {
- cout<<"\nSize of stack is: "<<countNum<<endl;
- }
- /////QUEUE AREA
- void posh()
- {
- string inp;
- if (bottom==m-1)
- {
- cout<<"Queue overflow"<<endl;
- }
- else
- {
- bottom++;
- queue[bottom] = inp;
- }
- }
- void del()
- {
- if (bottom==-1)
- {
- cout<<"Queue undeflow"<<endl;
- }
- else
- {
- cout<<"The popped element is: "<<queue[bottom]<<endl;
- bottom++;
- }
- }
- void disc()
- {
- if (down>=-1)
- {
- cout<<"Queue is empty"<<endl;
- }
- else
- {
- for(i=down;i <= bottom; i++)
- cout<<"The queue is: "<<queue[i]<<endl;
- }
- }
- void countt()
- {
- cout<<"The queue size is: "<<countQue<<endl;
- }
- int main()
- {
- int s,t;
- string val,inp;
- cout<<"(1) STACK"<<endl;
- cout<<"(2) QUEUE"<<endl;
- cout<<endl;
- cout<<"Enter your choice: ";
- cin>>t;
- switch(t){
- case 1:
- {
- do{
- //stack
- cout<<"(1) PUSH"<<endl;
- cout<<"(2) POP"<<endl;
- cout<<"(3) DISPLAY"<<endl;
- cout<<"(4) SHOW"<<endl;
- cout<<"(5) EXIT"<<endl;
- cout<<endl;
- cout<<"Enter your choice: ";
- cin>>s;
- switch(s)
- {
- case 1:
- {
- cout<<"Enter name: ";
- cin>>val;
- push(val);
- countNum++;
- break;
- }
- case 2:
- {
- pop();
- countNum--;
- break;
- }
- case 3:
- {
- display();
- break;
- }
- case 4:
- {
- count();
- break;
- }
- case 5:
- {
- exit(0);
- }
- }
- }while(s!=5);
- }
- case 2:
- {
- do{
- ////QUEUE
- cout<<"(1) PUSH"<<endl;
- cout<<"(2) POP"<<endl;
- cout<<"(3) DISPLAY"<<endl;
- cout<<"(4) SHOW"<<endl;
- cout<<"(5) EXIT"<<endl;
- cout<<endl;
- cout<<"Enter your choice: ";
- cin>>s;
- switch(s)
- {
- case 1:
- {
- cout<<"Enter name: ";
- cin>>val;
- posh();
- countQue++;
- break;
- }
- case 2:
- {
- del();
- countQue--;
- break;
- }
- case 3:
- {
- disc();
- break;
- }
- case 4:
- {
- countt();
- break;
- }
- case 5:
- {
- break;
- }
- }
- }while(s!=5);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement