//menu driven program of circular queue
#include<iostream.h>
#include<conio.h>
#include<process.h>
#define size 5
int front=-1,rear=-1;
void insert_CQ(int QUEUE[],int ELEMENT,int &front,int &rear)
{ if(rear==size-1)
rear=0;
else
rear++;
if(rear==front)
{ cout<<"\n Queue overflow";
exit(1);
}
QUEUE[rear]=ELEMENT;
if(front==-1)
front++;
}
void delete_CQ(int QUEUE[],int &front,int &rear)
{ int value;
if(front==-1)
{ cout<<"\n Queue underflow";
exit(1);
}
value=QUEUE[front];
cout<<"\n Element to be deleted is :"<<value;
if(front==rear)
front=rear=-1;
else
{ if(front==size-1)
front=0;
else
front++;
}
}
void display_CQ(int QUEUE[],int &front,int &rear)
{ if(front>=0)
{ if(front<=rear)
{ for(int p=front;p<rear;p++)
cout<<QUEUE[p]<<"<--";
cout<<QUEUE[rear];
}
else
{ for(int p=front;p<=size-1;p++)
cout<<QUEUE[p]<<"<--";
for(p=0;p<rear;p++)
cout<<QUEUE[p]<<"<--";
cout<<QUEUE[rear];
}
}
}
void main()
{ clrscr();
int ch,element,queue[20];
l:
cout<<"\n Press 1 for PUSHING"
<<"\n Press 2 for POPING"
<<"\n Press 3 for TRAVERSAL"
<<"\n Press 4 to EXIT\n";
cout<<"\n Enter your choice:";
cin>>ch;
if(ch==4)
{ cout<<"\n THANK YOU";
exit(0);
}
else if(ch==1)
{ cout<<"\n Enter the element to be inserted:";
cin>>element;
insert_CQ(queue,element,front,rear);
goto l;
}
else if(ch==2)
{ delete_CQ(queue,front,rear);
goto l;
}
else
{ display_CQ(queue,front,rear);
goto l;
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<process.h>
#define size 5
int front=-1,rear=-1;
void insert_CQ(int QUEUE[],int ELEMENT,int &front,int &rear)
{ if(rear==size-1)
rear=0;
else
rear++;
if(rear==front)
{ cout<<"\n Queue overflow";
exit(1);
}
QUEUE[rear]=ELEMENT;
if(front==-1)
front++;
}
void delete_CQ(int QUEUE[],int &front,int &rear)
{ int value;
if(front==-1)
{ cout<<"\n Queue underflow";
exit(1);
}
value=QUEUE[front];
cout<<"\n Element to be deleted is :"<<value;
if(front==rear)
front=rear=-1;
else
{ if(front==size-1)
front=0;
else
front++;
}
}
void display_CQ(int QUEUE[],int &front,int &rear)
{ if(front>=0)
{ if(front<=rear)
{ for(int p=front;p<rear;p++)
cout<<QUEUE[p]<<"<--";
cout<<QUEUE[rear];
}
else
{ for(int p=front;p<=size-1;p++)
cout<<QUEUE[p]<<"<--";
for(p=0;p<rear;p++)
cout<<QUEUE[p]<<"<--";
cout<<QUEUE[rear];
}
}
}
void main()
{ clrscr();
int ch,element,queue[20];
l:
cout<<"\n Press 1 for PUSHING"
<<"\n Press 2 for POPING"
<<"\n Press 3 for TRAVERSAL"
<<"\n Press 4 to EXIT\n";
cout<<"\n Enter your choice:";
cin>>ch;
if(ch==4)
{ cout<<"\n THANK YOU";
exit(0);
}
else if(ch==1)
{ cout<<"\n Enter the element to be inserted:";
cin>>element;
insert_CQ(queue,element,front,rear);
goto l;
}
else if(ch==2)
{ delete_CQ(queue,front,rear);
goto l;
}
else
{ display_CQ(queue,front,rear);
goto l;
}
getch();
}