Circular Queue in Data Structure

Circular Queue:

In a circular queue, when the rear or front reaches then the rear or front will be 0. The increment of the rear or front is:

MAXSIZE-1
rear=(rear+1) % MAX and front=(front+1) % MAX

 

Circular Queue in Data Structure

Algorithm for insertion into circular queue:

Algorithm fnCirQInsert(arrCQueue[], Data)
{
if(boolQfull==TRUE)
Queue is full;
else
{
arrCQueue[rear]=Data;
rear=(rear+1) % MAXSIZE;
boolQempty=FALSE;
if(rear==front)
boolQfull=TRUE;
}
} // End of Algorithm

Algorithm for deletion into circular queue:

Algorithm fnCirQDelete(arrCQueue[])
{
if(boolQempty==TRUE)
Queue is empty;
else
{
Data=arrCQueue[front];
front=(front+1) % MAXSIZE;
boolQfull=FALSE;
if(front==rear)
boolQempty=TRUE;
}
}