package 递归;
public class 汉诺塔 {
public static void main(String[] args) {
test01(5,"A","B","C");
}
//代码实现
public static void test01(int N ,String from, String to ,String help ){
if (N == 1){
System.out.println("move"+N+"from"+from+"to"+to);
}else {
//
test01(N-1,from,help,to);//先把N-1个盘子放到
System.out.println("move"+N+"from"+from+"to"+to);
test01(N-1,help,to,from);
}
}
}
java算法递归之汉诺塔
猜你喜欢
转载自blog.csdn.net/qq_42794826/article/details/108961394
今日推荐
周排行