Priority Queue in Data Structure

Priority Queue:

A priority queue is a collection of elements such that each element has been assigned priority such that the order in which elements are deleted and processed comes from the followings rules:

1. An element of higher priority is processed before any element of lower priority.
2. Two elements with the same priority are processed according to the order in which they are added to the queue.

There are two types of priority queues:

  • Ascending priority queue
  • Descending priority queue

Ascending priority queue:

Here the elements can be inserted arbitrarily but only the element with the smallest priority can be deleted.

Descending priority queue:

Here the elements can be inserted arbitrarily but only the element with the highest priority can be deleted.