Docstoc

queue

Document Sample
queue Powered By Docstoc
					#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class queue
{
 int number;
 queue *next;
 queue *front;
 queue *rear;
  public:
   void insertion();
   void deletion();
   void display();
};

void queue::insertion()
{
 int x;
 cout<<"\nEnter the number :";
 cin>>x;
 if(front==NULL)
 {
  rear=new queue;
  rear->number=x;
  rear->next=NULL;
  front=rear;
 }
 else
 {
  rear->next=new queue;
  rear=rear->next;
  rear->number=x;
  rear->next=NULL;
 }
}

void queue::deletion()
{
 queue *temp;
 if(front==NULL)
  cout<<"Queue is Empty \n";
 else
 {
  temp=new queue;
  temp=front;
  front=front->next;
  delete(temp);
 }
}
void queue::display()
{
 queue *temp;
 if(front==NULL)
  cout<<"Queue is Empty \n";
 else
 {
  temp=front;
  do
  {
   cout<<temp->number<<" ";
   temp=temp->next;
  } while(temp!=NULL);
 }
}

int main()
{
 queue *p;
 int fl;
 clrscr();
 do
 {
  cout<<"\n1.Insertion 2.Deletion 3.Display 4.Exit\n";
  cout<<"Enter your choice :";
  cin>>fl;
  switch(fl)
  {
   case 1:
   {
    p->insertion();
    break;
   }
   case 2:
   {
    p->deletion();
    break;
   }
   case 3:
   {
    p->display();
    break;
   }
   case 4:
   {
    exit(0);

  }
  default: cout<<"\nEnter correct choice \n";
 }
} while(fl!=4);
 getch();
 return 0;
}

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:9
posted:10/17/2012
language:
pages:3
Description: C programming, C programming