If you look at pseudocode from the Wikipedia link you provided, you will see an array called prev[] . This array contains for each node v in the graph the previous node u in the shortest path between the source code of node s and v . (This array is also called the predecessor or parent array.)
In other words, the shortest path between s and v :
s -> u -> v where u = prev[v]
There can be several nodes in the path from s to u between them, so to restore the path from s to v , you simply return along the path defined by the prev[] array using the code fragment below the main pseudocode ( target v ):
1 S β empty sequence 2 u β target 3 while prev[u] is defined: // Construct the shortest path with a stack S 4 insert u at the beginning of S // Push the vertex onto the stack 5 u β prev[u] // Traverse from target to source 6 end while
source share