A Priority Queue is a collection of elements such that each element has been assigned a priority and such that the order in which each elements are deleted and processed comes from the following rules :
A priority queue must at least support the following operations:
insert_with_priority: add an element to the queue with an associated priority
pull_highest_priority_element: remove the element from the queue that has the highest priority, and return it.
The algorithm to add an item in the priority queue
This algorithm adds an item with priority number M to a priority Queue maintained by a 2-dimensional array Queue.
1. Insert Item as the rear element in row M of Queue.
2. Exit.
The algorithm to delete an item from a priority queue
This algorithm deleted and processes the first element in a priority queue maintained by a 2-dimensional array Queue
1. [Find the first nonempty queue]
Find the smallest K such that FRONT[K]!=NULL.
2. Delete and process the front element in row K of Queue.
3. Exit.
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.