伪代码
1.
initialize(G,s)
for v in G
v.d=INF
s.d=0
2.
relax(u,v,w)
if v.d>u.d+w(u,v)
v.d=u.d+w(u,v)
3.
min-heapify(Q,i)
m=Q.length
if 2*i<=m
if Q[i].d>Q[2*i].d
smallest=2*i
else
smallest=i
if 2*i+1<=m
if Q[smallest].d>Q[2*i+1].d
smallest=2*i+1
//!!go on
if smallest != i
swap(Q[i],Q[smallest])
min-heapify(Q,smallest)
3.
extract-min(Q)
if Q.heap-size<1
error “Over flow” //check
x=Q[1]
swap (Q[1],Q[Q.length])
Q.heap-size=Q.heap-size-1
min-heapify(Q,1)
return x
4.
Dijkstra(G,s,w) //w!!record distance
//if only the shortest path from s to t is required, stop when t is removed from Q , i.e. when t=u
Q=new priority_queue(array) containing v (vertex in G) sorted by v.d
initialize(G,s)
while !Q.empty()
u=extract-min(Q)
for each edge(u,v) // each vertex v ∈ G.Adj[u]
relax(u,v,w)
5.
Bellman-ford(G,s,w)
initialize(G,s)
for i=1 to |G.v|-1
for each edge(u,v)
relax(u,v,w)
for each edge(u,v)
if v.d>u.d+w(u,v)
return false
return true
6.
Bi-Directional search
……