class DivideAndConquer
package Algorithm;
/**
* 分治算法解决汉诺塔移动问题
* @author coffee
* @Date 2021-04-06 10:18
*/
public class DivideAndConquer {
public static void main(String[] args) {
hanoiTower(2,'A','B','C');
}
public static void hanoiTower(int m,char a,char b,char c){
if (m == 1){
System.out.println("第1个盘 " + a + "->" + c);
}else {
//上面的盘移动到b
hanoiTower(m - 1,a,c,b);
//下面的移动到c
System.out.println("第" + m + "个盘 " + a + "->" + c);
//b上面的移动到c
hanoiTower(m - 1,b,a,c);
//i -> j i就相当于a,j相当于c,中间的b填剩下的即可
}
}
}