算法day13-----递归汉诺塔
public class a11 {
public static int count=0;
public static void main (String args[]) {
sort(3,'x','y','z');
System.out.println(count);
}
public static void sort(int n,char x,char y,char z) {
count++;
if(n==1) move(n,x,z);
else {
sort(n-1,x,z,y);
move(n,x,z);
sort(n-1,y,x,z);
}
}
public static void move(int n,char x,char z) {
System.out.println("第"+n+"从"+x+"到"+z);
}
}


浙公网安备 33010602011771号