Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 function Dijkstra(Graph, source):
- 2 dist[source] := 0 // Initializations
- 3 for each vertex v in Graph:
- 4 if v ≠ source
- 5 dist[v] := infinity // Unknown distance from source to v
- 6 previous[v] := undefined // Predecessor of v
- 7 end if
- 8 Q.add_with_priority(v,dist[v])
- 9 end for
- 10
- 11
- 12 while Q is not empty: // The main loop
- 13 u := Q.extract_min() // Remove and return best vertex
- 14 mark u as scanned
- if(u==drak)
- break
- 1 visited[] := empty sequence
- 2 u := target
- 3 while previous[u] is defined: // Construct the shortest path with a stack S
- 4 insert u at the beginning of S // Push the vertex into the stack
- 5 u := previous[u] // Traverse from target to source
- 6 end while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement