2
Circular queue in Data Structure “Queue can be implemented as simple queue, queue and circular queue. Circular queue c is also implemented as same as simple queue, the main difference is that in circular queue last element will again points to first element” In a standard queue data structure re-buffering problem occurs for each desuetude operation. To solve this problem by joining the front and rear ends of a queue to make the queue as a circular queue circular queue is a linear data structure. It follows FIFO Principle. * In circular queue the last node is connected back to the first node to make a circle. * Circular linked list fallow the First In First Out principle * Elements are added at the rear end and the elements are deleted at front end of the queue * Both the front and the rear pointers points to the beginning of the array. * It is also called as “Ring buffer”. * Items can inserted and deleted from a queue in O(1)time.

Circular Queue in Data Structure

Embed Size (px)

DESCRIPTION

cq

Citation preview

Circular queue in Data Structure

Queue can be implemented as simple queue, queue and circular queue. Circular queue c is also implemented as same as simple queue, the main difference is that in circular queue last element will again points to first element

In a standard queue data structure re-buffering problem occurs for each desuetude operation. To solve this problem by joining the front and rear ends of a queue to make the queue as a circular queue circular queue is a linear data structure. It follows

FIFO Principle. * In circular queue the last node is connected back to the first node to make a circle.

* Circular linked list fallow the First In First Out principle

* Elements are added at the rear end and the elements are deleted at front end of the queue

* Both the front and the rear pointers points to the beginning of the array.

* It is also called as Ring buffer.

* Items can inserted and deleted from a queue in O(1)time.

* If the front and rear are in adjacent locations (i.e rear following front) the message Queue is Full is displayed.

* If the value of front is -1 then it denotes that the queue is empty and that the element to be added be the first element in the queue. The values of front and rear in such a case are set to 0 and new element gets placed at 0th position.

* Some of the positions at the front end of the array might be empty. This happens if we have deleted some elements from the queue. When the value of rear is MAX-1 and the value of front is greater than 0. In such case value of rear is set to 0 and the element to be added is added to this position.

* The element is added at the rear position in case the value of front is either equal to or greater than 0 and the value of rear is less than MAX-1.

Thus, if we add 5 elements the value of front and rear becomes 0 and 4 respectively. The function display() displays the elements in the queue.