1.9. Priority queues

A priority queue is similar to a queue. The difference is that every item has an associated priority, and instead of removing the item that has been in the queue the longest, you remove the item with the highest priority. This is like a print queue, where higher priority jobs are printed first. Another use of a priority queue is simulations, where the priority of an event is the time that it will take place. Thus events can be scheduled in any order, and then simulated in chronological order.


For priority queues that could get very large, a heap is by far the best option. However, for small priority queues (say less that 50 elements) a simpler solution like a sorted array or a sorted linked list will probably run faster.

[Prev] [Next] [Up]

Last updated Sun Nov 28 22:04:38.0000000000 2004. Copyright Bruce Merry (bmerry '@' gmail dot. com).