This is because the Tail has no empty spot to point to after an element is inserted in the 14th position. In the above animation, if you tried to fill the queue completely you wouldn't be able to enqueue after the 13th position. Tail pointer - Points to the next empty spot in which the new element can be inserted.Or in other words, it points to the element to be removed if the dequeue operation is called. 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
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |