汉诺塔游戏规则
1、有三根相邻的柱子,标号为A,B,C。A柱子上从下到上按金字塔状叠放着n个不同大小的圆盘。现在把所有盘子一个一个移动到柱子B上,并且每次移动同一根柱子上都不能出现大盘子在小盘子上方。
public class HanNota {
public static void main(String[] args) {
Stack<Integer> a = new Stack<>();
Stack<Integer> b = new Stack<>();
Stack<Integer> c = new Stack<>();
for (int i = 0; i < 20; i++) {
a.push(i);
}
hanNoTa(a, b, c, a.size());
System.out.println(c);
}
public static void hanNoTa(Stack<Integer> a, Stack<Integer> b, Stack<Integer> c, int size) {
if (size == 1) {
c.push(a.pop());
} else {
hanNoTa(a, c, b, size - 1);
c.push(a.pop());
hanNoTa(b, a, c, size - 1);
}
}
}