Advertisement
adcorp

linked queue-final

Feb 12th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. #include<process.h>
  5.  
  6. struct ticket
  7. {
  8.  int tno;
  9.  char pname[25];
  10.  ticket *node;
  11. };
  12.  
  13. ticket *temp=NULL;
  14. ticket *front=NULL;
  15. ticket *rear=NULL;
  16.  
  17. void input();
  18. void Delete();
  19. void show();
  20.  
  21. void main()
  22. {
  23.  clrscr();
  24.  int ch;
  25.  char c;
  26.  do
  27.  {
  28.   cout<<"\n\n\t\t\tQUEUE MENU\n\tEnter\n";
  29.   cout<<"\t1.Input\n\t2.Delete\n\t3.Display\n\t4.Exit";
  30.   cout<<"\n\n\tENTER YOUR CHOICE:\t";
  31.   cin>>ch;
  32.   switch(ch)
  33.   {
  34.    case 1:
  35.       do
  36.       {
  37.        clrscr();
  38.        input();
  39.        cout<<"\n\n\t\tData Entered\n";
  40.        cout<<"\n\n Enter More Values (Y/N):  ";
  41.        cin>>c;
  42.       }while(c=='y'||c=='Y');
  43.       break;
  44.  
  45.    case 2:
  46.       clrscr();
  47.       cout<<"\n\t\tDeleted Data:\n\n" ;
  48.       Delete();
  49.       break;
  50.  
  51.    case 3:
  52.       clrscr();
  53.       cout<<"\n\t\t Queue:\n\n";
  54.       show();
  55.       break;
  56.  
  57.    case 4:
  58.       exit(0);
  59.       break;
  60.  
  61.    default:
  62.        cout<<"\n\t\tWRONG CHOICE\n\n\t\tENTER AGAIN\n\n";
  63.   }
  64.  }while(ch!=4);
  65. }
  66.  
  67. void input()
  68. {
  69.   temp=new ticket;
  70.   if(temp==NULL)
  71.    cout<<"\n MEMORY FULL\n";
  72.   else
  73.   {
  74.     cout<<"\n Enter Ticket Number: ";
  75.     cin>>temp->tno;
  76.     cout<<"\n Enter Passenger Name: ";
  77.     gets(temp->pname);
  78.     temp->node=NULL;
  79.  
  80.     if(front==NULL)
  81.     {
  82.      front=temp;
  83.      rear=temp;
  84.     }
  85.  
  86.     else
  87.     {
  88.      rear->node=temp;
  89.      rear=temp;
  90.     }
  91.   }
  92. }
  93.  
  94. void Delete()
  95. {
  96.  if(front==NULL)
  97.   cout<<"\n\t\tQUEUE EMPTY\n";
  98.  else
  99.  {
  100.   temp=front;
  101.   cout<<"\n Ticket number: "<<temp->tno;
  102.   cout<<"\n Passenger name: ";
  103.   puts(temp->pname);
  104.   front=front->node;
  105.   delete temp;
  106.  }
  107. }
  108.  
  109. void show()
  110. {
  111.  if(front==NULL)
  112.   cout<<"\n\t\tQUEUE EMPTY\n";
  113.  else
  114.  {
  115.    temp=front;
  116.    while(temp!=NULL)
  117.    {
  118.     cout<<"\n\t"<<temp->tno<<"\t\t";
  119.     puts(temp->pname);
  120.     temp=temp->node;
  121.    }
  122.  }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement