Code:
#include<iostream>
using namespace std;
int stack[20],value,n;
int top1=-1;int top2=9;
void push(int stack[],int& top1,int& top2,int value)
{if(n==1)
{if(top1==9)
cout<<"stack1 is full"<<endl;
else
{cout<<"enter value";
cin>>value;
stack[++top1]=value;
}
}
else if(n==2)
{if(top2==19)
cout<<"stack2 is full"<<endl;
else
{cout<<"enter value";
cin>>value;
stack[++top2]=value;
}
}
}
void pop(int stack[],int& top1,int& top2,int value)
{if(n==3)
{if(top1==-1)
cout<<"stack1 is empty"<<endl;
else
cout<<"popped element frm stack 1 is "<<stack[top1--]<<endl;
}else if(n==4)
{if(top2==9)
cout<<"stack 2 is empty"<<endl;
else
cout<<"poped value frm stack 2 is "<<stack[top2--]<<endl;
}
}
void show(int stack[])
{if(n==5)
{cout<<"stack 1 is"<<endl;
if(top1==-1)
cout<<"empty"<<endl;
else
for(int i=0;i<=9;i++)
{if(stack[i]==0)
break;
cout<<stack[i]<<endl;
}
}
if(n==6)
{cout<<"stack 2 is"<<endl;
if(top2==9)
cout<<"empty"<<endl;
else
for(int i=10;i<=19;i++)
{if(stack[i]==0)
break;
cout<<stack[i]<<endl;
}
}
}
void main()
{
for(char k='y';k!='n';)
{cout<<"Press 1 to insert the element in stack 1,\n 2 to insert the element in stack 2,\n 3 to delet the element from stack 1,\n 4 to delet the element from stack 2,\n 5 to show stack 1,\n 6 to show stack 2,\n";
cin>>n;
if(n==1)
push(stack,top1,top2,value);
if(n==2)
push(stack,top1,top2,value);
if(n==3)
pop(stack,top1,top2,value);
if(n==4)
pop(stack,top1,top2,value);
if(n==5)
show(stack);
if(n==6)
show(stack);
cout<<"do u want more y/n??"<<endl;
cin>>k;
}
}