Circular Queue
Circular Queue
BY:
M.SARANYA,AP/CSE
The Circular Queue is similar to a Linear Queue in the
sense that it follows the FIFO (First In First Out) principle but
differs in the fact that the last position is connected to the first
position, replicating a circle.
OPERATIONS :
Front - Used to get the starting element of the Circular Queue.
Rear - Used to get the end element of the Circular Queue.
enQueue(value) - Used to insert a new value in the Circular Queue.
This operation takes place from the end of the Queue.
deQueue() - Used to delete a value from the Circular Queue. This
operation takes place from the front of the Queue.
Enqueue(x) Operation
Check if the queue is empty, and set both Front and Rear to 0
Exit
Enqueue(x) Operation
viod enqueue(int X,circularqueue CQ)
{
if front==(rear+1)% arraysize
printf(“Queue is full”); {
elseif(rear==-1) rear=(rear+1)%arraysize;
{ CQ[rear]=X;
front=front+1; }
rear=rear+1; }
CQ[rear]=X;
}
else
dequeue
dequeue(x) Operation
viod dequeue(int X,circularqueue CQ)
{
if front==-1
printf(“Queue is empty”); {
elseif(front==rear) X=CQ[front];
{ front=(front+1)%arraysize;
X=CQ[front];
front=-1; }
rear=-1; }
}
else
Thank You