未访问
递归栈中
当前访问
已完成
访问顺序:空
选择起点,然后点击“开始 DFS”。
1 function DFS(node) {
2 if (visited.has(node)) return;
3 visited.add(node);
4 visit(node);
5 for (const next of graph[node]) {
6 if (!visited.has(next)) {
7 DFS(next);
8 }
9 }
10 return;
11 }
递归栈为空