Queues are not for iteration. The whole point of a queue is that you can only ever look at the element at the front of the queue.
If you want to iterate then I suggest just using an std::set
, which is ordered. When you want to modify an element, you'll have to remove it and reinsert it with the new key. You can get the highest priority element using mySet.begin()
(that returns an iterator to it).
Ideally, you'll want to use a heap. STL provides functions for making heaps, and that's what the std::priority_queue
uses. However, you can't modify keys in the heap because there is no interface for it.
If you manage the heap yourself then you can. However, you'll need to make use of the std::__adjust_heap
function from <heap.h>
, which is undocumented. You can read all about why this function is undocumented in this interview with Alexander Stepanov (inventor of the STL). It had to be "removed" because apparently the STL was too big, which is also what happened to hash maps from the original standard.