#include<iostream.h>
#include<conio.h>
struct node
{
int data;
node *next;
};
node* push(node* top);
node* pop(node* top);
void display(node* top);
void main()
{
clrscr();
int choice;
node* top;
top=NULL;
do
{
cout<<” 1 for push \n 2 for pop \n 3 for display \n 4 for quit”;
cin>>choice;
switch(choice)
{
case 1:
top= push(top);
break;
case 2: top=pop(top);
break;
case 3: display(top);
break;
}
}
while(choice!=4);
getch();
}
node* push(node* top)
{
node* x;
x=new node;
cout<<“enter value”;
cin>>x->data;
x->next=top;
top=x;
return top;
}
node* pop(node* top)
{ int v;
if(top==NULL)
{
cout<<“stack empty”;
return top;
}
else
{
node *x;
x=top;
top=top->next;
v=x->data;
cout<<“popped value”<<v;
delete x;
return top;
}
}
void display(node* top)
{
while(top!=NULL)
{
cout<<top->data;
cout<<“\n”;
top=top->next;
}
}