void hanoi(int n, char X, char Y, char Z) { if(n>0) { hanoi(n-1, Z, X, Y); cout<<Z<<"-->"<<X<<endl; hanoi(n-1, Y, X, Z); } }
public class HanNoidTower { /** * * @param z templates "from" * @param x templates "to" * @param y templates "through" * @param n move top n templates */ public void move(char z ,char x, char y, int n){ if(n==0) return ; move(z,y,x,n-1); System.out.println(z+"->"+x); move(y,x,z,n-1); } public static void main(String[] args){ HanNoidTower hanNoidTower = new HanNoidTower(); hanNoidTower.move('z','x','y',3); } }