BFS是继DFS后对图的又一种遍历方法。大家注意比较BFS算法与DFS的迭代算法,会有惊人的发现~
BFS(G,v)
Init queue
Add start point v into queue
visited[v]=true
while queue is not empty
t ← deQueue()
for each u connected to t
if u not visited
add u into queue
visited[u]=true