/*ALGORITHM:two ends
insertion:-at rear end i.e rightmost frst check if array is empty to enter element nd if yes thn enternd update rear
deletion:-at front end i.e leftmost frst check if array has somethng to delte if yes delete nd update front
*/
#include<iostream>
#include<conio.h>
using namespace std;

const int size=5;
class queue
{
int a[size];
int front,rear; //front-leftmost end nd rear-rightmost end
public:
queue()
{
front=rear=-1; //array indexing starts from 0 thus initialising both as -1 implies array to be empty
}
void ins();
void del();
void display();
};
void queue::ins()
{
int ele;
if(rear==size-1) //to check whether array is already full(if true no space to insert)
{
cout<<"\nOVERFLOW ERROR..."<<endl;
return;
}
else
{
cout<<"ENTER ELEMENT:";
cin>>ele;
if(rear==-1) //if ths is true thn it implies array is empty nd now bth front nd rear will be sme i.e oth index
{
front=rear=0;
a[rear]=ele;
}
else //if above condition is false thn it implies array alrady hve elements v jst need to increase in rear end by 1 and copy elemnt
{
a[++rear]=ele;
}
}
}
void queue::del()
{
if(front==-1) //to check whther array is empty(no element wud b there to delete)
{
cout<<"\nUNDERFLOW ERROR..."<<endl;
return;
}
else
{
cout<<a[front]<<" DELETED.."<<endl;
if(front==rear) //ths mns only 1 element is there in array nd aftr deleting it array wud b again empty so v need to initilise front and rear to -1 again
{
front=rear=-1;
}
else //here aftr deleting the elemnt array is nt empty it still contains elemnts so v increase front end by 1
{
front++;
}
}
}
void queue::display()
{
for(int i=front;i<=rear;i++)
cout<<a[i]<<" ";
}
int main()
{
int choice;
char ans;
queue q;
do
{
cout<<"MENU:"<<endl
<<"1.INSERT"<<endl
<<"2.DELETE"<<endl
<<"3.DISPLAY"<<endl
<<"4.EXIT"<<endl<<endl;
cout<<"ENTER YOUR CHOICE:";
cin>>choice;
switch(choice)
{
case 1:
q.ins();
break;
case 2:
q.del();
break;
case 3:
q.display();
break;
case 4:
exit(0);
}
cout<<"\nDO YOU WANT TO GO BACK TO MAIN MENU:";
cin>>ans;
}while(ans!='n');

getch();
return 0;
}

USERS VISITED
http://www.hitwebcounter.com/