PRIORITY QUEUE
A priority queue is a type of queue that arranges elements based on their
priority values. Each element has a priority associated. When we add an item, it
is inserted in a position based on its priority.
Elements with higher priority are typically retrieved or removed before
elements with lower priority.
TYPES OF PRIORITY QUEUE
● Ascending Order Priority Queue : In this queue, elements with lower
values have higher priority. For example, with elements 4, 6, 8, 9, and 10, 4
will be dequeued first since it has the smallest value, and the dequeue
operation will return 4.
● Descending order Priority Queue : Elements with higher values have
higher priority. In a priority queue, generally, the value of an element is
considered for assigning the priority. For example, the element with the
highest value is assigned the highest priority and the element with the lowest
value is assigned the lowest priority. The reverse case can also be used i.e.,
the element with the lowest value can be assigned the highest priority. Also,
the priority can be assigned according to our needs.
A priority queue is a type of queue that arranges elements based on their
priority values. Each element has a priority associated. When we add an item, it
is inserted in a position based on its priority.
Elements with higher priority are typically retrieved or removed before
elements with lower priority.
TYPES OF PRIORITY QUEUE
● Ascending Order Priority Queue : In this queue, elements with lower
values have higher priority. For example, with elements 4, 6, 8, 9, and 10, 4
will be dequeued first since it has the smallest value, and the dequeue
operation will return 4.
● Descending order Priority Queue : Elements with higher values have
higher priority. In a priority queue, generally, the value of an element is
considered for assigning the priority. For example, the element with the
highest value is assigned the highest priority and the element with the lowest
value is assigned the lowest priority. The reverse case can also be used i.e.,
the element with the lowest value can be assigned the highest priority. Also,
the priority can be assigned according to our needs.