常见算法.

Hanoi
class Program

    {

        static long count = 0;

        static void move(char x, char y)

        {

            Console.WriteLine("{0}--->{1}", x, y);

        }

        static void hanoi(int n, char one, char two, char three)

        {



            if (n != 0)

            {

                hanoi(n - 1, one, three, two);

                move(one, two);

                hanoi(n - 1, three, two, one);

            }

        }

        static void Main(string[] args)

        {

            int n = int.Parse(Console.ReadLine());

            hanoi(n, 'A', 'B', 'C');

            Console.WriteLine("done,count:{0}", count);

            Console.Read();

        }

    }

 

你可能感兴趣的:(算法)