PDA

View Full Version : std containers



joebanana
December 29th, 2007, 03:45 PM
I have a std::priority_queue container. How do I decrease one of it's elements priority? I know that its using vector for strorage. Should I get the element from priority_queue delete it from priority_queue decrease its key and readd it? Is this the right way. How can I access this element. Pls help.

thk
December 29th, 2007, 04:48 PM
I think the answer is that you are using the wrong data structure.

If you really want to do this, you will have to remove the element and re-add it into the queue. The storage elements are arranged as a heap so you cannot simply move them to any position.

joebanana
December 29th, 2007, 05:05 PM
I am implementing dijkstra. I have the java code and it's using priority_queue and there is a line q.decrease_key(w, value). Where q is priority_queue, w is object that is stored in q and value is the new value of priority.

amo-ej1
December 29th, 2007, 08:17 PM
I think you're stuck on some ugly java code then. If you look at the prototype of the Java priority queue (see http://java.sun.com/j2se/1.5.0/docs/api/java/util/PriorityQueue.html ) you will also notice there is no member function to lower the priority.

How is that decrease_key implemented ?