I'm trying to implement Prim's Algorithm and for that I need to have a decreaseKey method for a priority queue (to update the key value in a priority queue). Can I implement this in the STL Priority Queue?
If it helps, this is the algorithm I'm following:
- for each vertex u in graph G
- set key of u to INFINITY
- set parent of u to NIL
- set key of source vertex to 0
- en-queue to priority queue Q all vertices in graph with keys as above
- while Q is not empty
- pop vertex u with lowest key in Q
- for each adjacent vertex v of u do
- if (v is still in Q) and (key(u) + weight-function(u, v) < key(v)) then
- set u to be parent of v
- update v's key to equal key(u) + weight-function(u, v) // This part is giving me problems as I don't know how implement decreaseKey in priority queue
- if (v is still in Q) and (key(u) + weight-function(u, v) < key(v)) then