Advertisement
Guest User

Untitled

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