Priority Queue


Priority Queue

It is a special type of queue where elements are sorted on the basis of priority. It is a special type of line data structure where everything has a value associated with it. Suppose some features occur with the same priority, they will be organised according to FIFO policy.

Insertion in the priority queue takes place based on the arrival, while deletion in the priority queue occurs based on the priority. Priority queue is mainly used to implement the CPU scheduling algorithms.

There are two types of key lines that are discussed as follows -

  • Essential Keyboard - In the rising key, elements can be added in sequence, but only a few can be removed first. Suppose a list has elements 11, 52, 32 and 5 in the same order, so the installation can be done in the same order, but the order of removal of elements is 5, 11, 32, 52.
  • Key Drop Down - In the main drop line, elements can be added in sequence, but the biggest feature can be removed first. Suppose a list has elements 11, 52, 32 and 5 in the same order, so the installation can be done in the same order, but the order of removal is 52, 32, 11, 5.

The key line contains the following features:

  • Every element in the queue has some priority to do with it.
  • High priority elements will be deleted before deleting less priority elements.
  • If two elements in the queue have the same priority, then they will be organised using the FIFO principle.