If you iterate over the queue each time, you'll kill the performance guarantees of your algorithm. Instead, you should store the handle returned from the queue upon adding a new entry into the queue and use the handle to potentially update the priority of the entry. You might need to use one of the node-based priority queues, however.
You could e.g. use the Fibonacci Heap whose push()
yields a handle_type
. You'd store this value with your node and later use with increase()
or decrease()
to adjust the priority of the node in the heap.