Let Q[N] be an array implementation of a cicular queue, of size N and
type T. Then ‘front’ is a variable that point to the front element of the queue
and ‘rear’ is a variable that point to the last element of the queue.
Initially, rear=N-1 and front=N-1. Then the algorithm to add an element in the
queue is as follows:
1.
Start
2.
Check the conditions
if(rear=N-1)THEN
set rear to the first location, rear=0;
else
if(rear+1==front)THEN
print “The Queue is Full”;
else
++rear;
3.
Add the ‘item’ in the Queue.
Q[rear]=item;
4.
Exit
No comments:
Post a Comment