6. แยกย่อย

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 6-25  โปรแกรมแสดงการย้ายจานในหอคอยฮานอย
public class HanoiTower {
  public static void main(String[] args) {
    hanoi(3, "A", "B", "C");
  }
  public static void hanoi(int n, String a, String b, String c) {
    if (n == 0) return;
    hanoi(n - 1, a, c, b);
    System.out.println("move " + n + " : " + a + " -> " + c);
    hanoi(n - 1, b, a, c);
  }
}
©2009 S.Prasitjutrakul