

Here, the deletion happens from the front end. We will now perform the deQueue() operation. The integer '5' is added to the rear by performing enQueue(5). The integer '4' is added to the rear by performing enQueue(4). The front and rear have been marked and there is excess space in the end that we will fill up. The deletion is always done from the front.Ĭonsider a Circular Queue as shown below.

The insertion is always done at the rear. enQueue(item): insert a new value in the Circular Queue.Rear: obtain the rear element of the Circular Queue.Front: obtain the front element of the Circular Queue.This is where Circular Queues prove to be useful. To fill up the front vacancy, we need to shift all elements ahead and then add the new element from the rear.Once we delete an element from the front end, it can be seen that the newly created vacancy is not accessible easily because new elements can only be added from the rear end.The front and rear elements are as shown. Let us fill up the queue with random elements to utilise its maximum space.Here we have a regular queue with one element which will act as both the Front and Rear.This situation can be averted by using a Circular Queue where we can insert FIFO data until the queue reaches its maximum capacity. To utilize that vacancy in a regular queue, we would have to shift all elements ahead to insert an additional element in the rear. Once that limit is reached, no further additions can take place even if there is a vacancy in the front of the queue. When working with a normal queue, elements can be inserted into the queue till it becomes full.

Why Use Circular Queues Over Regular Queues Also known as Ring Buffer, Circular Queues were introduced to overcome a queue's limitation of not being able to utilize the vacant spaces left in the beginning once the rear reaches its end position. In this tutorial, we will learn about Circular Queues and their implementation.Ī Circular Queue is a linear data structure based on the First In First Out (FIFO) principle, wherein the last element is joined to the first element to create a circle.
