Queue : An Overview
Queue is a linear data structure based on FIFO (First-In-First-Out). The element inserted into the data structure will be the first component taken from the data structure. From this data structure, we can not add or remove random components. It is an ADT (Abstract Data Structure Type). There are two ends to this information structure, viz. Front and Rear. Data added from the last named REAR to the queue. Data removed from the beginning end called FRONT.
The process of inserting an element to the queueDataStructure is called Enqueue and the process of removing/deleting an element from the queueDataStructure is called Dequeue.
Types of Queue :
- Double-ended queue/ Deque:
Here, insert and delete operation can be occur at both ends that is front and rear of the queue.
Basic Operations in a Queue :
Working of a queue | How queue works?
Queue has two ends: front and rear. It is a linear data structurethat can insert data from one end and remove from the other only. We also know its working is based on FIFO. FIFO is abbreviation of First In First Out.
It is tested at first whether or not a queue is initialized. We set both front and back pointers to-1 at the moment of initialization, which means it has no components. Whenever an item is to be added, it is compulsory to verify whether or not it is complete. If it is not complete, increase the rear value by 1 and enqueue the element.Whenever an item is supposed to be removed, isEmpty condition must always be checked. Increase the front value by 1 if it is not empty and dequeue an element.
Applications of queue :
It is a simple data structure. We can implement it in different programming languages such as C, C++, C#, Java etc. with ease. It is quite easy to implement but still effective and applicable in real world scenarios. It is very much useful in the following cases:
- Serving requests on a single shared resource, like a printer, CPU task scheduling etc.
- In real life scenario, Call Center phone systems uses Queues to hold people calling them in an order, until a service representative is free.
- Handling of interrupts in real-time systems. The interrupts are handled in the same order as they arrive i.e. First come first served.
This data structure can be used whenever we need to manage any group of objects in an order in which the first one coming in, also gets out first while the others wait for their turn.
Was this article helpful?
We would love to hear from you. Must share your views in the comment section below. For more interesting and informative updates, keep visiting our Tech blogs