What are Circular Queues ?
A circular queue is one in which the insertion of new element is done at the very first location of the queue if the last location of the queue is full. Suppose if we have a Queue of n elements then after adding the element at the last index i.e. (n-1)th , as queue is starting with 0 index, the next element will be inserted at the very first location of the queue which was not possible in the simple linear queue. That's why linear queue leads to wastage of the memory, and this flaw of linear queue is overcome by circular queue.
So, in all we can say that the circular queue is a queue in which first element come right after the last element, that means a circular queue has a starting point but no end point.
While dealing with the circular queue we will use the following assumptions :
- Front will always be pointing to the first element of the queue.
- If Front=Rear, the queue will be empty.
- Each time a new element is inserted into the queue, the value of rear is incremented by one i.e. Rear = (Rear + 1);
- Each time when an existing element is deleted from the queue, the value of rear is incremented by one i.e. Front = (Front + 1);
Just like various other homogeneous data structures the main operations that can be performed on a circular queue are:
Show All Comments