
The following steps can be seen as a flow chart to the operation of the Circular Queue: This means that the position 0 will always contain an element which is not how an actual queue/circular queue works. This is because once an element is removed, the list automatically shifts all the other elements by one position to the left. Note: During a dequeue operation, the Head pointer will be incremented by 1 but no element will actually be removed from the queue.

To do this, we need to treat Lists like arrays, hence we will restrict its size.
ENQUEUE PYTHON HOW TO
Let's see how to implement it using the language agnostic method. I hope you now feel confident that you know what a circular queue is. For instance, Head = 14, Tail = 5 and Size of Queue = 15, then the number of elements = 15 - (14 - 5) = 6

Head pointer - Points to the front of the Queue.Observations based on the above animation: This is possible because the Head and Tail pointers are allowed to cross each other.Ĭheck out this animation to understand the circular queue a bit better. The Head can be greater than the Tail or vice-versa.The Tail and Head can point to the same location - this means the Queue is empty.This means that once the Head or Tail reaches the end of the Queue, it resets itself to 0. There is no need to reset Head and Tail pointers since they reset themselves.A Circular Queue can be seen as an improvement over the Linear Queue because: Circular Queues are widely used and are often tested on job interviews. Basic Python data structure concepts - listsīefore you go ahead and read this tutorial, I highly recommend you to read our previous tutorial on Queues as we will be building off of those concepts.Linear Queues (you can learn more here).To learn about Circular Queue, you should first have a good understanding of the following:

Last Updated: Wednesday 29 th December 2021 Prerequisites
