Open In App

Why can’t a Priority Queue wrap around like an ordinary Queue?

Priority Queue:

A priority queue is a special type of queue in which each element is assigned a priority value. And elements are served based on their priority. This means that elements with higher priority are served first. However, if elements with the same priority occur, they will be served in the order in which they were queued. A priority queue can be implemented using an array, a linked list, a heap data structure, or a binary search tree. Among these data structures, the heap data structure provides an efficient implementation of priority queues.

Queue Implementation with Array and Wrap Around:

A queue can be implemented using an array:

What is Wrap Around?

In a circular queue, To solve the problem of not being able to insert an item even if the queue is not full, the front and back arrows of the queue wrap around the beginning of the field as shown in the figure. This is called a ring queue or ring buffer. Note that after the back arrow is wrapped, it is now below the front arrow, i.e. the reverse of the original arrangement.

Fig 1.1 Wrap Around

Why can’t a priority queue wrap around like an ordinary queue?

Article Tags :