mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-08 05:26:07 +00:00
fix(csharp): Modify method name to PascalCase, simplify new expression (#840)
* Modify method name to PascalCase(array and linked list) * Modify method name to PascalCase(backtracking) * Modify method name to PascalCase(computational complexity) * Modify method name to PascalCase(divide and conquer) * Modify method name to PascalCase(dynamic programming) * Modify method name to PascalCase(graph) * Modify method name to PascalCase(greedy) * Modify method name to PascalCase(hashing) * Modify method name to PascalCase(heap) * Modify method name to PascalCase(searching) * Modify method name to PascalCase(sorting) * Modify method name to PascalCase(stack and queue) * Modify method name to PascalCase(tree) * local check
This commit is contained in:
@@ -8,7 +8,7 @@ namespace hello_algo.chapter_graph;
|
||||
|
||||
public class graph_dfs {
|
||||
/* 深度优先遍历 DFS 辅助函数 */
|
||||
public void dfs(GraphAdjList graph, HashSet<Vertex> visited, List<Vertex> res, Vertex vet) {
|
||||
public void Dfs(GraphAdjList graph, HashSet<Vertex> visited, List<Vertex> res, Vertex vet) {
|
||||
res.Add(vet); // 记录访问顶点
|
||||
visited.Add(vet); // 标记该顶点已被访问
|
||||
// 遍历该顶点的所有邻接顶点
|
||||
@@ -17,18 +17,18 @@ public class graph_dfs {
|
||||
continue; // 跳过已被访问过的顶点
|
||||
}
|
||||
// 递归访问邻接顶点
|
||||
dfs(graph, visited, res, adjVet);
|
||||
Dfs(graph, visited, res, adjVet);
|
||||
}
|
||||
}
|
||||
|
||||
/* 深度优先遍历 DFS */
|
||||
// 使用邻接表来表示图,以便获取指定顶点的所有邻接顶点
|
||||
public List<Vertex> graphDFS(GraphAdjList graph, Vertex startVet) {
|
||||
public List<Vertex> GraphDFS(GraphAdjList graph, Vertex startVet) {
|
||||
// 顶点遍历序列
|
||||
List<Vertex> res = new List<Vertex>();
|
||||
List<Vertex> res = new();
|
||||
// 哈希表,用于记录已被访问过的顶点
|
||||
HashSet<Vertex> visited = new HashSet<Vertex>();
|
||||
dfs(graph, visited, res, startVet);
|
||||
HashSet<Vertex> visited = new();
|
||||
Dfs(graph, visited, res, startVet);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -42,12 +42,12 @@ public class graph_dfs {
|
||||
new Vertex[2] { v[2], v[5] }, new Vertex[2] { v[4], v[5] }, new Vertex[2] { v[5], v[6] },
|
||||
};
|
||||
|
||||
GraphAdjList graph = new GraphAdjList(edges);
|
||||
GraphAdjList graph = new(edges);
|
||||
Console.WriteLine("\n初始化后,图为");
|
||||
graph.print();
|
||||
graph.Print();
|
||||
|
||||
/* 深度优先遍历 DFS */
|
||||
List<Vertex> res = graphDFS(graph, v[0]);
|
||||
List<Vertex> res = GraphDFS(graph, v[0]);
|
||||
Console.WriteLine("\n深度优先遍历(DFS)顶点序列为");
|
||||
Console.WriteLine(string.Join(" ", Vertex.VetsToVals(res)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user