Stack


PROGRAM:
#include<iostream.h>
void push();
void pop();
int s[5],top=0;
main()
{
int ch;
char c;
do
{
cout<<"\n1.PUSH";
cout<<"\n2.POP";
cout<<"\nEnter the choice:\n";
cin>>ch;
switch(ch)
{
 case 1:
   push();
   break;
 case 2:
   pop();
   break;

 default:
   cout<<"\nEnter the valid choice";
}
cout<<"\nDo you want to continue?";
cin>>c;
}while(c=='y'||c=='Y');
}
void push()
{
if(top==5)
cout<<"\nStack is full";
else
cout<<"\nEnter the element to be pushed:";
cin>>s[top];
top++;
}
void pop()
{
top=top-1;
if(top<0)
cout<<"\nstack is empty";
else
cout<<"\nPop out elements"<<s[top];
}

0 comments: