查看文章 |
汉诺塔Hanoi
2008-07-22 16:30
public static void Hanoi(int n, string a, string b, string c) { if (n == 1) { //move the one dish of a to c Console.WriteLine("{0} -> {1}", a, c); } else if (n > 1) { //move n-1 dishes of a to b Hanoi(n - 1, a, c, b); //move the bigest dish of a to c Console.WriteLine("{0} -> {1}", a, c); //move the n-1 dishes of c to c Hanoi(n - 1, b, a, c); } } |
最近读者: