- Hanoi:
public void move(int n,char a,char b,char c){
if(n==1){
System.out.println("move from "+a+" to "+c);
}else{
move(n-1, a,c,b);
move(1, a, b, c);
move(n-1, b, a, c);
}
}
- Queue:
public void move(int n,char a,char b,char c){
if(n==1){
System.out.println("move from "+a+" to "+c);
}else{
move(n-1, a,c,b);
move(1, a, b, c);
move(n-1, b, a, c);
}
}