Examples of Java data structures and algorithms: Hanoi the hannotta problem
- 2020-04-01 03:56:49
- OfStack
package al;
public class Hanoi {
public static void main(String[] args) {
Hanoi hanoi = new Hanoi();
hanoi.move(3, 'A', 'B', 'C');
}
public void move(int n, char from, char temp, char to) {
if(n == 1) {
System.out.println("Move 1 plate from " + from + " to " + to);
} else {
move(n-1, from, to, temp);
move(1, from, temp, to);
move(n-1, temp, from, to);
}
}
}