Circular queue Algorithm
Circular queue Algorithm
Enqueue()
step 1: If (front and rear == -1) otherwise goto step 2
1.1: set both to 0 and Insert element in rear position
step 2: If(rear + 1)%size==front, otherwise goto step 3
2.1: print “the queue is full”.
step 3:Increment the rear pointer using (rear + 1) % max.
step 3.1: Insert element in rear position
Dequeue()
step 1: If (front and rear == -1) otherwise goto step 2
step 1.1:print “the queue is empty”
step 2:If front equals rear otherwise goto step 3
step 2.1set both pointers back to -1.remove front position element
step 3:remove the value at the front position. Increment the front pointer using
(front + 1) % max.
Display()
step 1: If (front==0 and rear == -1) otherwise goto step 2
step 1.1:print “the queue is empty”
step 2: :if (front>rear) otherwise goto step 3
Step 2.1: initialize i=0
Step 2.2 if(i<=rear)otherwise goto step 2.3
Step 2.2.1 print queue[i]
Step 2.2.2 increment i goto step no 2.2
Step 2.3 initialize j=front
Step 2.4 if(j<=max-1)otherwise goto step 2.5
Step 2.4.1 print queue[j]
Step 2.4.2 increment j goto step no 2.4
Step 3: initialize i=front
Step 4 if(i<=rear)otherwise goto step 5
Step 4.1 print queue[i]
Step 4.2 increment i goto step no 4
step 5:End of display() method.