You are on page 1of 2

#include<iostream.

h>
#include<conio.h>
#include<stdio.h>
struct node
{char country[30];
node *link;
};
class stack
{
node *top;
public:
stack()
{top=NULL;}
void push();
void pop();
void display();
};
void stack::push()
{node *temp=new node;
gets(temp->country);
temp->link=top;
top=temp;
}
void stack::pop()
{
if(top!=NULL)
{
node *temp=top;
top=top->link;
delete temp;
}
else
cout<<"stack is empty";
}
void stack::display()
{node *temp=top;
while(temp!=NULL)
{cout<<temp->country<<"->";
temp=temp->link;
}
}
void main()
{clrscr();
stack st;
char ch;
do
{
cout<<"PRESS :\n\n "
<<"p for push\n"
<<"o for pop\n"
<<"d for display\n"
<<"q for quit\n";
cin>>ch;
switch(ch)
{
case 'p' : st.push();
break;
case 'o' : st.pop();
break;
case 'd' : st.display();
}
getch();
clrscr();
}
while(ch!='q') ;
}

You might also like