Queue and Circular Queue

Queue and Circular Queue

Queues is a kind of conceptual data type where substance are inserted one end (rear end) known as enqueue procedure and detected from the other end(front end) known as dequeue process.

This makes the queue a First-In-First-Out (FIFO) data arrangement.

The queue performs the function of a buffer.

Circular Queue is a linear data arrangement in which the operations are performed based on FIFO (First In First Out) code and the last place is linked back to the first place to make a circle. It is also called ‘Ring Buffer’.

Queue is a structure in which insertion are made at one end and deletion are made at other ends. A Circular list is a list implemented in a finite size array. Front of the queue is pointed by variable FRONT from where deletion are done. Back of the queue is pointed by variable REAR were the insertion are done. In a circular queue, in case after a number of insertions and deletions. In a circular queue, in case after a number of insertion and deletions, REAR reaches the last location, and if further insertions and deletions, REAR  reaches the last location, and if further insertions are to be made, REAR is modified to point back to beginning of array.

                Similarly if FRONT reach the last location of array and if deletion is made then FRONT is modified to O. Circular queue is like a snake in a hollow circular tube chasing its tail. So long the number of elements in queue does not exceed the maximum size of array, there is no problem in inserting the element.

CIRCULAR-Q-INSERT(QUEUE, N, FRONT, REAR, DATA): this algorithm inserts DATA into the queue implemented in array QUEUE  which can hold N elements.

  1. If(FRONT =O and REAR =N-1) OR (FRONT =REAR+1)



End if


FRONT          ——-       O

REAR       ——–            O


If (REAR=N-1)

              REAR    ———     O


                                     REAR       ———-    REAR+1

End if

  • QUEUE [REAR]————-DATA; insert element

CIRCULAR-Q-DELETE (QUEUE, N, FRONT, REAR);: this algorithm delete an element from queue pointed by FRONT and store it in DATA


                             Print: QUEUE UNDERFLOW


End if

  • If (FRONT =REAR)

                             FRONT———                   NULL

                             REAR ———    NULL   


                        If(FRONT =N-1)

FRONT  ———   O


      FRONT ————– FRONT +1

End if

  • Return

Delete process is used to delete a constituent from round Queue.

In order to remove an element from Circular Queue first, we have to make sure whether Circular Queue is vacant or not. If round Queue is blank then we can not delete an component from Circular Queue. This condition is known as “Underflow”.

If Circular line is not underflow then we can delete an element from Circular Queue.

After deleting an component from Circular Queue we have to set the value of FRONT and REAR variables according to the essentials in the Circular Queue.

Leave a Reply

Your email address will not be published. Required fields are marked *