内容纲要
225讲汉诺塔、八皇后
汉诺塔
- 我不能理解
package main.daytwo;
public class HanoiTower {
public static void main(String[] args) {
Tower tower = new Tower();
tower.move(3,'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.假设有2个盘。则需要把上面所有的盘看成一个盘。移动到b。借助c
move(num - 1,a,c,b);
System.out.println(a + "->" + b);
//2.然后把num那个盘移动到c。
System.out.println(a + "->" + c);
//3.最后把num-1那一堆盘移动到c,借助b
move(num-1,b,a,c);
System.out.println(b + "->" + c);
}
}
}
八皇后
public class EightQueen{
public static void main(String[] args){
}
}
class T{
public void
}