📅  最后修改于: 2022-03-11 14:45:24.114000             🧑  作者: Mango
Initialize an empty stack for storage of nodes, S.
For each vertex u, define u.visited to be false.
Push the root (first node to be visited) onto S.
While S is not empty:
Pop the first element in S, u.
If u.visited = false, then:
U.visited = true
for each unvisited neighbor w of u:
Push w into S.
End process when all nodes have been visited.