Queue in Data Structure

Sk Akib Jabed
2 min readJul 3, 2021

The queue data structure is linear. It follows the FIFO approach i.e. First In First Out or Last In Last Out.
In the queue, the order of insertion is the same as the order of deletion of elements because of the FIFO approach.

Queues are mostly used whenever there is a single resource and multiple users want to use that resource. For example, in threads and CPU scheduling algorithms.

A data structure queue is analogous to a queue in real life. For example, people waiting in a queue to buy movie tickets.

Representation of a Queue

Just like a stack, the queue is also an abstract data type but it follows the FIFO approach. In the queue, we always remove the least recently added element.

A queue is open at both ends, unlike a stack. Thus we perform deletion and insertion operations at two different ends in a queue.The two ends of the queue are the Front and Rear respectively.

Front points to the index of the queue from where we can delete an element. Rear points to that index of the queue from where we insert elements.

We can represent the queue as follows:

Types of Queue

There are various types of queue data structures such as:
1. Linear queue
2. Circular queue
3. Deque
4. Priority queue

Let us see each of them in detail now:

1. Linear queue

A linear queue is a simple queue in which insertion occurs at one end and deletion occurs at the other end.
In a linear queue, we are sometimes not able to utilize memory effectively. This is because insertion can be performed only at the rear end.

Basic operations on Linear Queue:

The basic operations that we can perform on a queue are:

a. enqueue(): To insert an element into the queue.

b. dequeue(): To delete an element from a queue.

c. peek(): To print/display the element at the front without deleting it.

d. isfull(): To check if the queue is full or not.

e. isempty(): To check if the queue is empty or not.

Out of the given operations, the first two operations are the most important. The rest three are used to improve the efficiency of the first two operations while implementation.

Originally published at https://rob-tics.blogspot.com.

--

--