汉诺塔算法不错,收藏了!

static void Main(string[] args)
{
            Hanoi(
5, 'A', 'B', 'C');
            Console.ReadLine();
        }

       
public static void Hanoi(int n, char A, char B, char C)
        {
           
//汉诺塔问题
           
//将n个盘子从A座借助B座,移到C座
            if (n == 1) Move(A, C);
           
else
            {
                Hanoi(n
- 1, A, C, B);
                Move(A, C);
                Hanoi(n
- 1, B, A, C);
            }

        }

       
public static void Move(char startPlace, char endPlace)
        {
            Console.WriteLine(
"Move {0} To {1}", startPlace, endPlace);
        }

转载于:https://www.cnblogs.com/qqhfeng/archive/2011/08/18/2144151.html

你可能感兴趣的:(汉诺塔算法不错,收藏了!)