Reformat the C# codes.

Disable creating new line before open brace.
This commit is contained in:
krahets
2023-04-23 03:03:12 +08:00
parent ac6eece4f3
commit 73dcb4cea9
49 changed files with 561 additions and 1135 deletions

View File

@@ -9,18 +9,14 @@ using NUnit.Framework;
namespace hello_algo.chapter_graph;
public class graph_dfs
{
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); // 标记该顶点已被访问
// 遍历该顶点的所有邻接顶点
foreach (Vertex adjVet in graph.adjList[vet])
{
if (visited.Contains(adjVet))
{
foreach (Vertex adjVet in graph.adjList[vet]) {
if (visited.Contains(adjVet)) {
continue; // 跳过已被访问过的顶点
}
// 递归访问邻接顶点
@@ -30,8 +26,7 @@ public class graph_dfs
/* 深度优先遍历 DFS */
// 使用邻接表来表示图,以便获取指定顶点的所有邻接顶点
public List<Vertex> graphDFS(GraphAdjList graph, Vertex startVet)
{
public List<Vertex> graphDFS(GraphAdjList graph, Vertex startVet) {
// 顶点遍历序列
List<Vertex> res = new List<Vertex>();
// 哈希表,用于记录已被访问过的顶点
@@ -41,8 +36,7 @@ public class graph_dfs
}
[Test]
public void Test()
{
public void Test() {
/* 初始化无向图 */
Vertex[] v = Vertex.ValsToVets(new int[7] { 0, 1, 2, 3, 4, 5, 6 });
Vertex[][] edges = new Vertex[6][]
@@ -60,4 +54,4 @@ public class graph_dfs
Console.WriteLine("\n深度优先遍历DFS顶点序列为");
Console.WriteLine(string.Join(" ", Vertex.VetsToVals(res)));
}
}
}