You are on page 1of 1

PROGRAM CODE:

#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{ clrscr();
int TOS=0,i,a[5],value,ch;
cout<<endl<<"Enter the operation you ant to perform";
cout<<endl<<"1:Push"<<endl<<"2:Pop"<<endl<<"3:Exit"<<endl;
cin>>ch;
do {if(ch==1)
{if(TOS>4)
{cout<<"Stack overflow";}
else
{
cout<<endl<<"Enter the element you want to insert: ";
cin>>value;
TOS=TOS+1;
a[TOS]=value;
}
cout<<endl<<"Enter "<<endl<<"1:Push"<<endl<<"2:Pop"<<endl<<"3:Exit"<<endl;
cin>>ch;
}
if(ch==2)
{cout<<endl<<"The top most element is: "<<endl;
if(TOS==-1)
{cout<<"Stack Underflow"<<endl;}
else
{value= a[TOS];
TOS=TOS-1;
cout<<value<<endl;
}
cout<<endl<<"Enter "<<endl<<"1:Push"<<endl<<"2:Pop"<<endl<<"3:Exit"<<endl;
cin>>ch;
} if(ch==3)
{exit(0);}
}while(ch==1 || ch==2);
}

You might also like