public class HanoiTowerTest {
private int i = 1;
public static void main(String[] args) {
HanoiTowerTest hanoi = new HanoiTowerTest();
hanoi.hanoiTower(4,'A','B','C');
}
public void hanoiTower(int n,char from,char dependOn,char to ) {
if(n == 1) {
move(1,from,to);
}else {
/**
* 1.将n-1个盘子从A借助C移动到B**/
hanoiTower(n-1,from,to,dependOn);
/**
* 将第n个盘子(底盘)从A移动到C**/
move(n,from,to);
f1();
/**
* 将n-1个盘子从B借助A移动到C**/
hanoiTower(n-1,dependOn,from,to);
}
}
private void move(int n, char from, char to) {
System.out.println("第"+i+++"步,从"+from+"----->"+to);
}
public void f1() {
}
}