mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-10 22:46:07 +00:00
build
This commit is contained in:
@@ -532,7 +532,7 @@ BFS 通常借助队列来实现。队列具有“先入先出”的性质,这
|
||||
|
||||
```csharp title="graph_dfs.cs"
|
||||
/* 深度优先遍历 DFS 辅助函数 */
|
||||
void Dfs(GraphAdjList graph, HashSet<Vertex> visited, List<Vertex> res, Vertex vet) {
|
||||
void DFS(GraphAdjList graph, HashSet<Vertex> visited, List<Vertex> res, Vertex vet) {
|
||||
res.Add(vet); // 记录访问顶点
|
||||
visited.Add(vet); // 标记该顶点已被访问
|
||||
// 遍历该顶点的所有邻接顶点
|
||||
@@ -541,7 +541,7 @@ BFS 通常借助队列来实现。队列具有“先入先出”的性质,这
|
||||
continue; // 跳过已被访问过的顶点
|
||||
}
|
||||
// 递归访问邻接顶点
|
||||
Dfs(graph, visited, res, adjVet);
|
||||
DFS(graph, visited, res, adjVet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -552,7 +552,7 @@ BFS 通常借助队列来实现。队列具有“先入先出”的性质,这
|
||||
List<Vertex> res = new();
|
||||
// 哈希表,用于记录已被访问过的顶点
|
||||
HashSet<Vertex> visited = new();
|
||||
Dfs(graph, visited, res, startVet);
|
||||
DFS(graph, visited, res, startVet);
|
||||
return res;
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user