stack operation

/* program to perfortm the following operation on stack
1) push 2) pop 3)is empty 4)is full 5) peep */



#include
#include
#include
void push();
void pop();
void peep();
void isempty();
void isfull();
int max=20;
int stack[20],top=-1;

void main()
{
int choice=1;
clrscr();
while(choice)
{
cout<<"\n1.psuh |";
cout<<"\n2.pop |";
cout<<"\n3.peep |";
cout<<"\n4.is empty:|";
cout<<"\n5.is full :|";
cout<<"\n0.exit |";
cout<<"\nenter your choice ==> ";
cin>>choice;
switch(choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
peep();
break;
case 4:
isempty();
break;
case 5:
isfull();
break;
default:
cout<<"\nwrong choice: \n";
}
}
}
void push()
{
int pushed;
if(top==(max-1))
cout<<"\n\t\tstack is over flow\n";
else
{
cout<<" \n\t\tenter the element to push ==> ";
cin>>pushed;
top=top+1;
stack[top]=pushed;
}
}
void pop()
{
if(top==-1)
cout<<"\n\t\tstack is under flow \n";
else
{
cout<<"\n\t\tpop value is ==> "< top=top-1;
}
}
void peep()
{
int x;
cout<<"\n\t\tenter element to display ==> ";
cin>>x;
cout<<"\n\t\tyour element is ==> "< }
void isempty()
{
if(top==-1)
cout<<"\n\t\tstack is empty ";
}
void isfull()
{
if (top==max)
cout<<"\n\t\tstack is full ";
}

0 comments:

Post a Comment