Académique Documents
Professionnel Documents
Culture Documents
#include<iostream.h>
#include<conio.h>
#include<process.h>
# define SIZE 20
void PUSH(int stack[],int item, int &top)
{if(top==size-1)
{cout<<”\n OVERFLOW”;
exit(1);
}
else
{ top++;
stack[top]=item;
}
}
int POP(int stack[], int &top)
{ if(top==-1)
{ cout<<”\n UNDERFLOW”;
Exit(1);
}
else
{ int ret=stack[top];
top--;
}
return (ret);
}
void DISPLAY(int stack[], int top)
{ if (top==-1)
cout<,”Stack empty”;
else
{cout<,stack[top]<<”<--“ <<endl;
for(int i=top-1;i>=0;i--)
cout<,stack[i]<,endl;
}
}
void main()
{int stack[size],item, top=-1, res;
char ch=‟y‟;
clrscr();
while(ch==‟y‟ || ch==‟Y‟)
{cout<<”\n Enter the ITEM for insertion:”;
cin>>item;
PUSH(stack,item,top);
cout<<”\n The stack is :\n”;
DISPLAY(stack,top);
cout<<”\n Want to insert more elements? (y/n)”;
cin>>ch;
}
cout<<”\n Deletion of elements:\n”;
ch=‟y‟;
while(ch==‟y‟ || ch==‟Y‟)
{
res=POP(stack,top);
cout<<”\n Deleted element is:”<< res;
cout<<”\n The stack is :\n”;
DISPLAY(stack,top);
cout<<”\n Want to delete more elements? (y/n)”;
cin>>ch;
}
getch();
}