#include<iostream.h>
#include<conio.h>
void main()
{
int stack[5],ch;
int n=0;
char choice;
clrscr();
do
{
cout<<"\n\n";
cout<<"\nenter the choice::";
cout<<"\n1. push";
cout<<"\n2. pop";
cout<<"\n3. view";
cin>>ch;
if(ch==1)
{
if(n==5)
cout<<"\nstack overflow!!";
else
{
int ele;
cout<<"\nenter the element to be pushed::";
cin>>ele;
stack[n]=ele;
n++;
}
}
else
if(ch==2)
{
if(n==-1)
cout<<"\nstack underflow";
else
{
n--;
cout<<"\nElement pop";
}
}
else
if(ch==3)
{
for(int i=0; i<n;i++)
cout<<stack[i];
}
else
cout<<"\ninvalid choice";
cout<<"\nDo
you wish to continue\n";
cin>>choice;
}
while(choice=='y'||
choice=='Y');
}
0 Comments