Queue is another common data structure that places elements in sequence, such as stack. The line is using the FIFO (First In First Out) method, where the first item in the line will be the first to be released by the line. Or it is called a two-hole pipe but that pipe is one way so the first thing that comes in will come out first in the pipe.

Let's look at a real example: A line of people waiting in the driveway. A new guy would join the end of the line, while the person in front of the line left the line and entered the area and ordered his food first before the last guy entered in that queue.

Basic operations of a queue

  • Enqueue() — Used to insert the elements at the end of the queue
  • Dequeue() — Used to remove the element from the start of the queue
  • isEmpty() — It returns true if the queue doesn’t contain any elements.
  • Top() — It returns the first element of the queue.
  • peek() − Gets the element at the front of the queue without removing it.
  • isfull() −isfull() − It checks if the queue is full

Queue is further divided into 4 types:

  1. Simple Queue
  2. Circular Queue
  3. Priority Queue
  4. Double Ended Queue

Simple Queue

In Simple Queue, the insertion occurs from the end while the removal occurs from front. The end where the insertion took place is known as the rear end, and the end where the removal took place is known as the front end. It strictly adheres to FIFO law.

Circular Queue

In the Circular Queue, all nodes are represented as circles. It is the same as the Simple Queue except that the last part of the queue is connected to the first element. It is also known as the Ring Buffer, as all endings are connected at one end.

Priority Queue

It is a special type of queue where elements are sorted on the basis of priority. It is a special type of line data structure where everything has a value associated with it. Suppose some features occur with the same priority, they will be organised according to FIFO policy.

Double Ended Queue

In Deque or Double Ended Queue, insertion and removal can be done from both ends of the queue from the front or back. It means we can add and remove elements to both ends of the front and back of the queue. Deque can be used as a palindrome check means that if we read the string from both ends, then the string will be the same. It can also be used as a stack for some operations.