Linier Queue

#include<iostream>
#include<conio.h>
#include<process.h>
#define SIZE 10
using namespace std;
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]<<" ";
}
int main()
{
  char choice;
  int ch,num;
  queue ob;
  do
  {
  system("cls");
  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;
  system("cls");
   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();
}

No comments:

Post a Comment