#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;
     }
   }
  }

Recommended Answers

All 2 Replies

what's your question about queues ? Don't just post code and expect us to guess what you want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.