Search code examples
algorithmpriority-queue

How to use a Priority Queue?


Will a priority queue work if I want to process elements in FIFO, but have priority to an element that is greater than a certain number? What do I use if I want FIFO but also want some element to have priority if it is greater than 60?

Thanks!


Solution

  • Yes, you use a priority queue. If the element's priority is less than your threshold amount (such as 60), then simply assign it a constant priority (such as 1). Those lower elements will go in the queue FIFO.