#include<iostream.h>
#include<conio.h>
#include<process.h>
const int Max=100;
void push(int s[],int data,int &top)
{
if(top==Max-1)
cout<<"Stack Overflow";
else
{
top=top+1;
s[top]=data;
}
}
void pop(int s[],int &top)
{
if(top==-1)
cout<<"Stack Underflow";
else
{
cout<<"The element to be deleted is"<<s[top];
top=top-1;
}
}
void display(int s[],int top)
{
if(top==-1)
cout<<"Stack Underflow";
else
{
for(int i=top;i>=0;i--)
cout<<s[i]<<"\n";
}
}
void main()
{
clrscr();
int s[Max],top=-1,d,option;
while(1)
{
cout<<"\n1.Push \n 2.Pop \n 3.Display\n 4.Exit\n Enter your Option";
cin>>option;
switch(option)
{
case 1:
cout<<"\nEnter the element to be pushed";
cin>>d;
push(s,d,top);
break;
case 2:
pop(s,top);
break;
case 3:
display(s,top);
break;
case 4:
exit(0);
}
}
}
#include<conio.h>
#include<process.h>
const int Max=100;
void push(int s[],int data,int &top)
{
if(top==Max-1)
cout<<"Stack Overflow";
else
{
top=top+1;
s[top]=data;
}
}
void pop(int s[],int &top)
{
if(top==-1)
cout<<"Stack Underflow";
else
{
cout<<"The element to be deleted is"<<s[top];
top=top-1;
}
}
void display(int s[],int top)
{
if(top==-1)
cout<<"Stack Underflow";
else
{
for(int i=top;i>=0;i--)
cout<<s[i]<<"\n";
}
}
void main()
{
clrscr();
int s[Max],top=-1,d,option;
while(1)
{
cout<<"\n1.Push \n 2.Pop \n 3.Display\n 4.Exit\n Enter your Option";
cin>>option;
switch(option)
{
case 1:
cout<<"\nEnter the element to be pushed";
cin>>d;
push(s,d,top);
break;
case 2:
pop(s,top);
break;
case 3:
display(s,top);
break;
case 4:
exit(0);
}
}
}