mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-13 13:19:46 +08:00
Finetune
This commit is contained in:
@@ -33,7 +33,7 @@ public class hanota {
|
||||
}
|
||||
|
||||
/* 求解汉诺塔 */
|
||||
static void hanota(List<Integer> A, List<Integer> B, List<Integer> C) {
|
||||
static void solveHanota(List<Integer> A, List<Integer> B, List<Integer> C) {
|
||||
int n = A.size();
|
||||
// 将 A 顶部 n 个圆盘借助 B 移到 C
|
||||
dfs(n, A, B, C);
|
||||
@@ -49,7 +49,7 @@ public class hanota {
|
||||
System.out.println("B = " + B);
|
||||
System.out.println("C = " + C);
|
||||
|
||||
hanota(A, B, C);
|
||||
solveHanota(A, B, C);
|
||||
|
||||
System.out.println("圆盘移动完成后:");
|
||||
System.out.println("A = " + A);
|
||||
|
||||
@@ -23,9 +23,9 @@ def dfs(graph: GraphAdjList, visited: set[Vertex], res: list[Vertex], vet: Verte
|
||||
dfs(graph, visited, res, adjVet)
|
||||
|
||||
|
||||
# 使用邻接表来表示图,以便获取指定顶点的所有邻接顶点
|
||||
def graph_dfs(graph: GraphAdjList, start_vet: Vertex) -> list[Vertex]:
|
||||
"""深度优先遍历 DFS"""
|
||||
# 使用邻接表来表示图,以便获取指定顶点的所有邻接顶点
|
||||
# 顶点遍历序列
|
||||
res = []
|
||||
# 哈希表,用于记录已被访问过的顶点
|
||||
|
||||
Reference in New Issue
Block a user