programming-examples/java/Basics/Hanoi Algorithm Recursion.java

24 lines
570 B
Java
Raw Normal View History

2019-11-18 14:44:36 +01:00
Hanoi Algorithm Recursion
public class HanoiAlgorithmRecursion {
public static void movetower( int height, int fromT, int toT, int usingT ) {
if( height > 0 ) {
movetower( height - 1, fromT, usingT, toT );
moveDisk( fromT, toT );
movetower( height - 1, usingT, toT, fromT );
}
}
public static void moveDisk( int takeoff, int puton ) {
System.out.println( takeoff + "->" + puton );
}
public static void main( String argv[] ) {
int numberOfDisks = 3;
movetower( numberOfDisks, 1, 3, 2 );
}
}