数据算法之汉诺塔

static void Main(string[] args)
{

Console.WriteLine("请输入圆盘个数:");
int N = 0;
N = Convert.ToInt32(Console.ReadLine());//强转
hanoi('A', 'B', 'C', N);
Console.WriteLine();
Console.ReadKey();
}
static void hanoi(char A, char B, char C, int count)
{
if (count == 1)
Console.WriteLine("1: " + A + "->" + B);
else
{
hanoi(A, C, B, count - 1);//从A借助C移动到B
Console.WriteLine(count + ": " + A + "->" + B);
hanoi(C, B, A, count - 1);//从C借助B移动到A
}
}

posted @ 2016-10-21 22:57  路边有一棵草  阅读(137)  评论(0编辑  收藏  举报