A queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out.
Implementation Options of Queue
Common operations of Queue
Linear queue (Array implementation)
Creation of Linear Queue ( Array implementation )
isEmpty / isFull operation
Time complexity of linear Queue ( Array implementation )
In linear queue when we dequeue value from queue, dequeue value from the start. so at the time of dequeue we can’t use this front space. If we utilize space then we should implement Circular queue.
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.
How Circular Queue works
Enqueue operation of Circular Queue (Array implementation)
If we are trying to dequeue an element and there is no element in the queue then we simply return error message.
Linear queue ( Linked list implementation )
In dequeue we have two operation over here.
One if the queue is empty then simply return error message.
then if there is at least one element in the queue then we can perform dequeue successfully .