汉诺塔问题:打印n层汉诺塔从最左边移动到最右边的全部过程。
public static void hanoi(int n) {if (n > 0) {func(n, "left", "right", "mid");}}public static void func(int N, String from, String to, String other) {if (N == 1) { // base case 最上面的圆盘想怎么动就怎么动System.out.println("Move 1 from " + from + " to " + to);} else {func(N - 1, from, other, to);System.out.println("Move " + N + " from " + from + " to " + to);func(N - 1, other, to, from);}}
