Aim: WAP To Perform Push, Pop, and Traverse in A Stack of Integers
Aim: WAP To Perform Push, Pop, and Traverse in A Stack of Integers
integers.
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
void main()
{
clrscr();
int stack[SIZE], item, top=-1, res;
char ch='y';
while(ch=='y' || ch=='Y')
{
cout<<"Enter item for insertion: ";
cin>>item;
res = push(stack, top, item);
if(res == -1)
{
cout<<"Overflow..!!..Aborting..Press a key to
exit..\n";
getch();
exit(1);
}
cout<<"\nThe Stack now is:\n";
display(stack, top);
cout<<"\nWant to enter more ? (y/n).. ";
cin>>ch;
}
cout<<"Now the deletion of elements starts..\n";
ch='y';
while(ch=='y' || ch=='Y')
{
res = pop(stack, top);
if(res==-1)
{
cout<<"\nUnderflow..!!..Aborting..!!..Press a key to
exit..\n";
getch();
exit(2);
}
else
{
cout<<"\nElement deleted is: "<<res<<endl;
cout<<"\nThe Stack now is:\n";
display(stack, top);
}
cout<<"Want to delete more ? (y/n).. ";
cin>>ch;
}
getch();
}