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循环让我感到困惑。