Queue is FIFO data structure, in which the element added first would be deleted first. The basic operations of queues are dequeue and enqueue. Operation which is performed in the front(queue) is called enqueue and operation which is performed in the end(queue) is called dequeue. Elements are arranged sequentially in a queue, so they are called as linear data structures.
EXAMPLES:
1.The one who visits the stop first is served first.
2.Waiting list for train and bus tickets
3.Disk scheduling and CPU task scheduling
There are 4 types of queues, they are:
1.Linear Queue
2.Priority Queue
3.Circular Queue
4.Dequeue
-> LINEAR QUEUES:
Insertion happens from 1 end and deletion happens from another end. The end where insertion occurs is called the rear end, and the end where deletion occurs is called front end. It follows the FIFO rule. Here is an example,
10 20 30 ----
front rear
---- 20 30 -----
front rear
We can see that front points to next element, and element previously pointed was deleted. But there's a drawback, insertion is only done from rear end.
CIRCULAR QUEUE:
Here, all nodes are presented as circular. It's alike to linear Queue but the last element is connected to first element. It's called Ring Buffer since all ends are connected.
The drawback in linear queue could be solved by using circular queue. If empty space is available, the new element could be added in the empty space by just incrementing rear value.
PRIORITY QUEUE:
The priority queue is a unique type of Queue in which every element has priority correlated with it. According to the priority of an element, they are arranged in the priority queue. If same priority elements occurs, they are set out accordingly(FIFO).
Here, insertion happens according to the arrival and deletion happens according to the priority.
DEQUEUE:
Dequeue doesn't follow the FIFO principle. Insertion and deletion is possible from both ends.
Top comments (0)