A queue is a linear data structure that stores elements in sequential order. It follows the FIFO (First-In-First-Out) principle, which means that the first element added to the queue will be the first one to be removed.
In the image below, you can see a queue of people in a supermarket. People are standing in line, waiting for their turn to be served by the cashier. This is a perfect illustration of how a queue works.
The first person in line will be served first, and as each person is served, they are removed from the front of the line while new customers are added to the back of the line. This creates a first-in, first-out (FIFO) order, ensuring that the customers are served in the order they arrive.
In this tutorial, we will discuss the different types of queue data structures, their properties, and an example illustration for each.
Types of Queues
The following are the four different types of queues:
- Simple Queue
- Circular Queue
- Priority Queue
- Double Ended Queue
Simple Queue
A simple queue, also known as a linear queue, is a basic queue data structure that follows the FIFO (First In First Out) principle. In a simple queue, elements are inserted from one end, called the rear, and removed from the other end, called the front.
To learn more, please read our comprehensive tutorial on Queue Data Structure.
Circular Queue
A circular queue, also known as a circular buffer or a ring buffer, is a type of queue data structure that uses a fixed-size buffer. In a circular queue, the last element points to the first element, forming a circle.
This type of queue is more efficient than a simple queue for situations where the queue needs to be accessed repeatedly.
Priority Queue
A priority queue is a type of queue data structure where each element has a priority assigned to it. Elements with higher priority are dequeued first. Values are added to the queue in the order they arrive, but when it comes to removing values from the queue, priority is taken into consideration.
This type of queue is commonly used in simulation and event-driven systems.
Double Ended Queue
A double-ended queue, also known as a deque (pronounced “deck”), is a type of queue data structure that allows the insertion and removal of elements from both ends. Thus, it does not adhere to the FIFO (First In First Out) principle.
This type of queue can be used as a stack or a simple queue, depending on the application.