/*PROGRAM TO IMPLEMENT DELETION IN A QUEUE USING ARRAY*/
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#define MAX 5
void main()
{
int i,a[MAX],rear=-1,front=-1,n;
char ch;
clrscr();
do
{
if(rear>=MAX-1)
{
cout<<“Queue is full”<<endl;
break;
}
else
{
rear++;
cout<<“Enter the number to be inserted: “;
cin>>n;
a[rear]=n;
front=0;
}
cout<<“Do you want to insert more numbers: “;
cin>>ch;
}while(ch==’y’||ch==’Y’);
cout<<“Elements of queue are: “<<endl;
for(i=front;i<=rear;i++)
{
cout<<a[i]<<“\t”;
}
cout<<endl;
//DELETION OF ELEMENTS FROM QUEUE
cout<<“Do you want to delete elements from queue?? “;
cin>>ch;
if(ch==’y’||ch==’Y’)
{
do
{
if(front<0 && rear<0)
{
cout<<“Queue is empty”<<endl;
break;
}
else
{
n=a[front];
cout<<“Deleted element is: “<<n<<endl;
front++;
}
if(front>MAX-1 || front>rear)
{
rear=-1;
front=-1;
}
cout<<“Do you want to delete more elements from the queue??”;
cin>>ch;
}while(ch==’y’||ch==’Y’);
if(front>=0)
{
cout<<“Elements remaining in the queue are: “<<endl;
for(i=front;i<=rear;i++)
{
cout<<a[i]<<“\t”;
}
}
}
else
cout<<“Press any key to exit”<<endl;
getch();
}