http://c.biancheng.net/algorithm/tower-of-hanoi.html
java题解
public class HannuoiTower {
public static void main(String[] args) {
Tower tower = new Tower();
tower.move(5,'A','B','C');
}
}
class Tower {
public void move(int num,char a,char b,char c) {
if(num == 1) {
System.out.println(a + "->" + c);
}else {
//如果有多个盘,可以看成两个,最下面和最上面的所有盘
// 1.先移动上面所有的盘到b,借助c
move(num-1,a,c,b);
//2.把最下面的这个盘移动到c
System.out.println(a+"->"+c);
//3.把b塔所有的盘,移动到c,借助a
move(num-1,b,a,c);
}
}
}