You are on page 1of 2

#include<iostream.

h>
#include<conio.h>
#include<stdlib.h>
struct node
{
long int pno;
char pname[20];
int ticketno;
node *next;
};
class queueoftrain
{
node *rear,*front;
public:
queueoftrain()
{
rear=NULL;
front=NULL;
}
void insert();
void del();
};
void queueoftrain::insert(void)
{
rear=new node;
cout<<"insert ticket number"<<endl;
cin>>rear->ticketno;
cout<<"enter passenger name"<<endl;
cin>>rear->pname;
if(front==NULL)
{
front=rear;
front->next=NULL;
}
else
{
rear->next=front;
front=rear;
}
}
void queueoftrain::del(void)
{
if(front==NULL)
{
cout<<"stack is empty";
exit(0);
}
else
{
rear=front;
front=front->next;
cout<<"passenger information"<<endl;
cout<<rear->ticketno<<endl;
cout<<rear->pname;
delete rear;
}
}
void main()
{clrscr();
queueoftrain 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.insert();
break;
case 'o' :
break;
case 'd' : st.del();
}
getch();
clrscr();
}
while(ch!='q') ;
}

You might also like