Queue | Data Structure
Queue?. The first thing that comes in mind by this word is a ‘Line’, a line of people waiting for their turn. In Data Structure it works on a same principle.
Queue is an Interface in Data Structure that works on the principle of First In First Out (FIFO). The element inserted first would be the first element to be removed from the Queue. The first element to be remove from the beginning is called Head and the last element to be added in a Queue is called Rear. We cannot add data randomly in a Queue.
Let us consider an example of a queue of a Canteen, the first customer standing in a queue will be the first customer to be served while the last customer standing at the end of queue will wait for his turn until he becomes the first. Similarly the element we want to delete will be at the first whereas the new element that is added will be added at the last.
There are differnt Types of Queues in Data Structure.
- Simple Queue:
As it is clear by it’s name a simple Queue perform operations simply. Addition is done at the last and deletion is done at the beginning. All the nodes are connected to each other in the list the pointer of the first element is null and similarly the pointer to the last points at null.
2. Circular Queue:
In a circular queue elements are also connected to each other but the difference is that the address of the last element is linked to the address of the first element making it a circular queue.
3. Priority Queue:
Priority as can be identified by the name , so by using this type of queue we can prioritize our elements that which element we want to delete first so that element will move towards the first position.
4. DeQueue/Doubly Queue:
This type of queue allows insertion and deletion of elements at both sides Head and Rear.
Unlike every class and Interface Queue also have it’s own methods to perform operations, which are ;
1: add(Object)
2: remove()
3: element()
4: poll()
5: peek()
6: offer(Object)
Queue is one of the many important concepts in Data Structures that can be used whenever we want to manage a group of objects in order,to which first thing coming first while the others have to wait for their turn.