• Difficulty Level : Easy
• Last Updated : 27 May, 2022

A Queue is a linear data structure. This data structure follows a particular order in which the operations are performed. The order is First In First Out (FIFO). It means that the element that is inserted first in the queue will come out first and the element that is inserted last will come out last. It is an ordered list in which insertion of an element is done from one end which is known as the rear end and deletion of an element is done from the other which is known as the front end. Similar to stacks, multiple operations can be performed on the queue. When an element is inserted in a queue, then the operation is known as Enqueue and when an element is deleted from the queue, then the operation is known as Dequeue.  It is important to know that we cannot insert an element if the size of the queue is full and cannot delete an element when the queue itself is empty. If we try to insert an element even after the queue is full, then such a condition is known as overflow whereas, if we try to delete an element even after the queue is empty then such a condition is known as underflow.

Primary Queue Operations:

• void enqueue(float value): When this operation is performed, an element is inserted in the queue at the end i.e. at the rear end.
• int dequeue():   When this operation is performed, an element is removed from the front end and is returned.

Auxiliary Queue Operations:

• int front(): This operation will return the element at the front without removing it.
• int rear(): This operation will return the element at the rear without removing it.
• int isEmpty(): This operation indicates whether the queue is empty or not.
• int size(): This operation will return the size of the queue i.e. the total number of elements.

Types of Queues:

• Simple Queue: Simple queue also known as a linear queue is the most basic version of a queue. Here, insertion of an element i.e. the Enqueue operation takes place at the rear end and removal of an element i.e. the Dequeue operation takes place at the front end.
• Circular Queue:  In a circular queue, the element of the queue act as a circular ring. The working of a circular queue is similar to the linear queue except for the fact that the last element is connected to the first element. Its advantage is that the memory is utilized in a better way. This is because if there is an empty space i.e. if no element is present at a certain position in the queue, then an element can be easily added at that position.
• Priority Queue: This queue is a special type of queue. Its specialty is that it arranges the elements in a queue based on some priority. The priority can be something where the element with the highest value has the priority so it creates a queue with decreasing order of values. The priority can also be such that the element with the lowest value gets the highest priority so in turn it creates a queue with increasing order of values.
• Dequeue: Dequeue is also known as Double Ended Queue. As the name suggests double ended, it means that an element can be inserted or removed from both the ends of the queue unlike the other queues in which it can be done only from one end. Because of this property it may not obey the First In First Out property.

Implementation of Queue:

• Sequential allocation: A queue can be implemented using an array. It can organize a limited number of elements.
• Linked list allocation:  A queue can be implemented using a linked list. It can organize an unlimited number of elements.

Applications of Queue:

• Multi programming: Multi programming means when multiple programs are running in the main memory. It is essential to organize these multiple programs and these multiple programs are organized as queues.
• Network: In a network, a queue is used in devices such as a router or a switch. another application of a queue is a mail queue which is a directory that stores data and controls files for mail messages.
• Job Scheduling: The computer has a task to execute a particular number of jobs that are scheduled to be executed one after another. These jobs are assigned to the processor one by one which is organized using a queue.
• Shared resources: Queues are used as waiting lists for a single shared resource.

Real-time application of Queue:

• ATM Booth Line
• Ticket Counter Line
• Key press sequence on the keyboard
• Waiting time of each customer at call centers.

• A large amount of data can be managed efficiently with ease.
• Operations such as insertion and deletion can be performed with ease as it follows the first in first out rule.
• Queues are useful when a particular service is used by multiple consumers.
• Queues are fast in speed for data inter-process communication.
• Queues can be used in the implementation of other data structures.