September 25, 2012 / IST / Language, Software Development.

A linear queue models the FIFO(first in first out) data structure, much like a line in real life. The first person in line will be the first person served, in queues the first element to be added is the first that can be removed. The only adding point is to the end of the list and the only removal point is the beginning of the list.

/*Q-11a-> Wap in C++ To Implement Linear Queue Using Array*/

#include<iostream.h>
#include<conio.h>
#include<process.h>
#define SIZE 10
static int front=0;
static int end=-1;
class queue
{
  private:
	  int ar[SIZE];
  public:
	  void insert(int item);
	  void delque();
	  void viewque();
};
void queue::insert(int item)
{
   if(end==SIZE-1)
      cout<<"\nThe Queue is Full!!!";
   else
     { ar[++end]=item;
       cout<<"\nElement succesfully inserted in the Queue!!!";
     }
}
void queue::delque()
{
  if(end<0)
    cout<<"\nQueue Under flow!!!";
  else
   { front++;
     cout<<"\nElement sucessfully deleted from the Queue!!!";
   }
}
void queue::viewque()
{ if(end<0)
    cout<<"\nThe Queue is Empty it cannot be Viewed!!!";
  else
    for(int i=front;i<=end;i++)
      cout<<ar[i]<<" ";
}
void main()
{
  clrscr();
  char choice;
  int ch,num;
  queue ob;
  do
  {
  clrscr();
  cout<<"\n\n\t\t\tQ U E U E   O P E R A T I O N S";
  cout<<"\n\t\t\t--------------------------------";
  cout<<"\n\n1.INSERT";
  cout<<"\n2.DELETE";
  cout<<"\n3.DISPLAY";
  cout<<"\n4.EXIT";
  cout<<"\n\nEnter your choice:";
  cin>>ch;
   switch(ch)
   {
     case 1: cout<<"\nEnter the Element you want to Push:";
	     cin>>num;
	     ob.insert(num);
	      break;
     case 2: ob.delque(); break;
     case 3: ob.viewque(); break;
     case 4: exit(0);
     default: cout<<"\nPlease Enter a Valid Choice(1-4)!!!";
   }
  cout<<"\nDo you want to Continue(Y/N):";
  cin>>choice;
  }while(choice=='y' || choice=='Y');

 getch();
}