i2tutorials

Data Structures-Circular queue

Circular queue

 

Circular queue is based on the principle of FIFO or First-In-First-Out, only exception being the last element is connected to the first one. This is also known as ring buffer

 

Operations of circular queue

Various operations performed by the circular queue are as follows:

  1. Front(): It gets the front element from the queue.
  2. End(): It gets the rear element from the queue.
  3. enQueue(): It inserts new value in the queue.
  4. deQueue(): It deletes new value in the queue. 

 

Applications of circular queue

Applications of circular queue are as follows:

  1. It provides memory management.
  2. The operating system uses it to insert and execute processes.
  3. Traffic control is one of the best examples of circular queue. 

 

Enqueue operation

Queues can be inserted when they are not full, and there are two such scenarios:

  1. When rear!=max-1, then the rear value is incremented to mod, and the new value obtained is inserted at the rear end.
  2. When front!=0 and rear=max-1, then the value for rear is set to 0, and a new element is inserted. 

 

The two situations in which the element cannot be inserted are as follows:

  1. When the front==0 and rear=max-1.
  2. When front==rear-1

 

Dequeue operations

 

Reference

Circular Queue

Exit mobile version