//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Example 4.15 on page 83
//  The Towers of Hanoi


public class Ex0415
{ public static void main(String[] args)
  { runHanoi(4,'A','B','C');
  }
  
  public static void runHanoi(int n, char x, char y, char z)
  { if (n==1)  // basis
      System.out.println("Move top disk from peg " + x
                       + " to peg " + z);
    else       // recursion
    { runHanoi(n-1,x,z,y);
      runHanoi(1,x,y,z);
      runHanoi(n-1,y,x,z);
    }
  }
}
