public class $ {
public static void main(String... _) {
test('A', 'B', 'C', 3);
}
/**
* 借助A,移动盘子:B->C
*
* @param a
* 盘子A
* @param b
* 盘子B
* @param c
* 盘子C
* @param n
* 数量
*/
private static void test(char a, char b, char c, int n) {
if (n == 1) {
move(b, c);
return;
}
test(c, b, a, n - 1);
move(b, c);
test(b, a, c, n - 1);
}
private static void move(char a, char b) {
System.out.println(a + "==>" + b);
}
}
05-05
05-05
05-05
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交