如果您从给出的Wikipedia链接中查看伪代码,则会在其中看到一个名为的数组
prev[]。对于图中的每个节点
v* ,此数组均包含源节点 s 与 v 之间最短路径中的 前一个 节点 u 。(此数组也称为 前置 数组或
父 数组。) ***
换句话说, s 和 v 之间 的 最短路径是:
s -> u -> vwhere u = prev[v]
从 s 到 u 的路径之间可能有多个节点,因此要重构从 s 到 v 的路径,您只需
prev[]使用主伪代码(
目标 为 v )下面的代码片段沿数组定义的路径返回:
1 S ← empty sequence2 u ← target3 while prev[u] is defined: // Construct the shortest path with a stack S4 insert u at the beginning of S // Push the vertex onto the stack5 u ← prev[u] // Traverse from target to source6 end while



