📜  dfs 算法 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:55.986000             🧑  作者: Mango

代码示例3
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.