/*PROGRAM TO DELETE ELEMENTS FROM CIRCULAR QUEUE USING ARRAY*/
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#define MAX 5
void main()
{
int front=-1,rear=-1,i,a[MAX],item;
char ch;
clrscr();
do
{
if((front==0 && rear==MAX-1)||(front==rear+1))
{
cout<<“Queue is full”<<endl;
break;
}
else if(front==-1 && rear==-1)
{
rear=0;
front=0;
cout<<“Enter the element you want to insert: “;
cin>>item;
a[rear]=item;
}
else if(rear==MAX-1 && front!=0)
{
rear=0;
cout<<“Enter the element you want to insert: “;
cin>>item;
a[rear]=item;
}
else
{
rear++;
cout<<“Enter the element you want to insert: “;
cin>>item;
a[rear]=item;
}
cout<<“Do you want to insert more elements ?? “;
cin>>ch;
}while(ch==’y’);
cout<<“Elements in the queue are: “<<endl;
for(i=front;i<=rear;i++)
{
cout<<a[i]<<“\t”;
}
//DELETION OF ELEMENTS FROM CIRCULAR QUEUE
cout<<endl<<“Do you want to perform deletion on circular queue??”;
cin>>ch;
if(ch==’y’)
{
do
{
if(front<0)
{
cout<<“Queue is empty”<<endl;
break;
}
else if(front==rear)
{
item=a[front];
cout<<“Deleted item is: “<<item<<endl;
front=-1;
rear=-1;
}
else if(front==MAX-1)
{
item=a[front];
cout<<“Deleted item is: “<<item<<endl;
front=0;
}
else
{
item=a[front];
cout<<“Deleted item is: “<<item<<endl;
front++;
}
cout<<“Do you want to continue deletion?? “;
cin>>ch;
}while(ch==’y’);
if(front!=-1)
{
cout<<“Remaining elements in the queue are:”<<endl;
for(i=front;i<=rear;i++)
{
cout<<a[i]<<“\t”;
}
}
}
else
cout<<“!!Press any key to exit!!”<<endl;
getch();
}