DFS和BFS有人可以为我解释这个

时间:2016-12-01 10:51:50

标签: pseudocode breadth-first-search depth-first-search

BREADTH-FIRST-SEARCH(G,v)
 Q←new Queue()
 visited←[]
 Q.enqueue(v)
 WHILE Q is not empty
 u←q.dequeue()
 IF u is not in visited
 visited.append(u)
 FOR all edges, e, from u
 Q.enqueue(e.to)
 RETURN visited

DEPTH-FIRST-SEARCH (G, v)
 S←new Stack()
 visited←[]
 S.push(v)
 WHILE S is not empty
 u←S.pop()
 IF u is not in visited
 visited.append(u)
 FOR all edges, e, from u, S.push(e.to)
 RETURN visited

有人可以解释这个伪代码的for循环,我理解其他所有内容但for循环让我感到困惑。

0 个答案:

没有答案