Circular Queue
Circular Queue
Circular Queue
Prerequisite – Queues
Circular Queue is a linear data structure in which the operations are performed based on FIFO
(First In First Out) principle and the last position is connected back to the first position to make a
circle. It is also called ‘Ring Buffer’.
In a normal Queue, we can insert elements until queue becomes full. But once queue becomes
full, we can not insert the next element even if there is a space in front of queue.
Circular Queue
In a circular queue, all nodes are treated as circular. Last node is connected back to the first
node.
Circular queue is also called as Ring Buffer.
It is an abstract data type.
Circular queue contains a collection of data which allows insertion of data at the end of the
queue and deletion of data at the beginning of the queue.
The above figure shows the structure of circular queue. It stores an element in a circular way and
performs the operations according to its FIFO structure.
#include<stdio.h>
#include<cstdlib>
#define max 6
int q[10],front=0,rear=-1;
int main()
{
int ch;
void insert();
void delet();
void display();
Output:
1.Insert
2. Display
3. Delete