广度优先搜索BFS
给定无向图G和源点s,遍历图。
BFS(G,s)
for each vertex u in G
u.color = white //所有点置为未扫描
endif
s.color = black //设置源点s为当前扫描点
Q = new queue //新建空队列
Q.add(s) //加入源点s
while(Q)
u = Q.dequeue //取队列首节点
for each vertex v connect with u
if(v.color == white)
Q.add(v)
v.color = black
endif
endwhile
广度优先遍历演示地址