@Test
public void hanoTest() {
hano('A', 'B', 'C', 1);
System.out.println("count: " + count);
}
public void hano(char A, char B, char C, int n) {
if (n > 0) {
//步骤1 按ACB数序执行N-1的汉诺塔移动
hano(A, C, B, n - 1);
//步骤2 执行最大盘子移动
System.out.println("move " + n + " : " + A + " -> " + C);
//步骤3 按BAC数序执行N-1的汉诺塔移动
hano(B, A, C, n - 1);
count++;
}
}
网友评论