In this tutorial, you will learn different types of queues with along with illustration.
A queue is a useful data structure in programming. It is similar to the ticket queue outside a cinema hall, where the first person entering the queue is the first person who gets the ticket.
There are four different types of queues:
In a simple queue, insertion takes place at the rear and removal occurs at the front. It strictly follows the FIFO (First in First out) rule.
Simple Queue Representation
In a circular queue, the last element points to the first element making a circular link.
Circular Queue RepresentationThe main advantage of a circular queue over a simple queue is better memory utilization. If the last position is full and the first position is empty, we can insert an element in the first position. This action is not possible in a simple queue.
A priority queue is a special type of queue in which each element is associated with a priority and is served according to its priority. If elements with the same priority occur, they are served according to their order in the queue.
Priority Queue Representation
Insertion occurs based on the arrival of the values and removal occurs based on priority.
In a double ended queue, insertion and removal of elements can be performed from either from the front or rear. Thus, it does not follow the FIFO (First In First Out) rule.
Deque Representation
119 docs|30 tests
|
1. What is a queue in the context of computer science? |
2. How is a queue different from a stack? |
3. What are some real-life examples of queues? |
4. How are queues implemented in computer programming? |
5. What are the applications of queues in computer science? |
|
Explore Courses for Computer Science Engineering (CSE) exam
|