算法:汉诺塔

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);
    }
}

你可能感兴趣的:(算法)