0
#include<iostream.h>
#include<conio.h>
#include<process.h>
const int max=5;
class queue
 {
  int r;
  int f;
  int q[max];
  int temp;
  public:
  queue(int l,int m,int p){r=l;f=m;temp=p;}
  void insertrear(int item);
  void deletefront();
  void display();
 };
  void queue::insertrear(int item)
   {
    if(r<(max-1))
     {
      r++;
      q[r]=item;
     }
    else
     {
      cout<<"\nQ is full"<<endl;
     }
  }
 void queue::deletefront()
  {
   if(f<r)
    {
     cout<<"\nDeleted item is "<<q[f]<<endl;
     f++;
    }
   else
    {
     f=0,r=-1;
     cout<<"\nQueue is empty";
    }
  }
 void queue::display()
  {
   temp=f;
   if(temp>r)
    {
     cout<<"\nQueue is empty";
    }
     while(temp<=r)
      {
       cout<<"\n"<<q[temp];
       temp++;
     }
   }
 void main()
  {
   clrscr();
   queue x(-1,0,0);
   int item,ch;
   for(;;)
    {
     cout<<"\nEnter-> \n1:Insertrear 2:Deletefront 3:display 4:exit\t";
     cin>>ch;
     switch(ch)
      {
       case 1:  cout<<"\nEnter the item:\t";
		cin>>item;
		x.insertrear(item);
		break;
       case 2:  x.deletefront();
		break;
       case 3:  x.display();
		break;
       case 4:  exit(0);
		break;
     }
   }
  }
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.