Queue
First In First Out (FIFO)
Last updated
First In First Out (FIFO)
Last updated
Elements are always added to the back and removed from the front.
Example: A line of people waiting for a bus. The person who is at the beginning of the line is the first one to enter the bus.
Enqueue - If the queue is not full, this function adds an element to the back of the queue, else it prints “OverFlow”.
Dequeue - If the queue is not empty, this function removes the element from the front of the queue, else it prints “UnderFlow”.
In a double-ended queue, characters can be inserted and deleted from both the front and back of the queue.
A circular queue is an improvement over the standard queue structure. In a standard queue, when an element is deleted, the vacant space is not reutilized. However, in a circular queue, vacant spaces are reutilized.
While inserting elements, when you reach the end of an array and you need to insert another element, you must insert that element at the beginning (given that the first element has been deleted and the space is vacant).