Understanding priority queue

A priority queue is a special type of queue where items are inserted and removed based on their priority. In the programming world, the use of the priority queue is immense. For example, say that we have a very large e-mail queue system where we send a monthly newsletter through a queue system. What if we need to send an urgent email to a user using the same queue functionality? Since the general queue principle is to add the item at the end, the process of sending that message will be very much delayed. In order to solve the problem, we can use the priority queue. In such a case, we assign a priority to each node and sort them based on that priority. An item with higher priority will go to the top of the list and will be dequeued earlier.

We can take two approaches in building a priority queue.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset