汉罗塔问题
/// <summary>
/// 汉罗塔问题的递归解
/// </summary>
/// <param name="start"></param>
/// <param name="middle"></param>
/// <param name="end"></param>
/// <param name="num"></param>
/// <remarks>
///
/// 算法目的: 把是start柱子上的木块移动到end柱子上
///
/// 当start柱子上只有两个圆环时,把两个圆环放到end柱子上要借助middle柱子,
/// 这样start柱子上有n个圆环时,要先把第n个圆环上的n-1各圆环移动到middle柱子上,
/// 然后再把第n个圆环移动到end柱子上,
/// 然后再把middle柱子上的n-1个圆环移动到end柱子上, 依次递归上去直到把start柱子只有1个圆环时移动该圆环到end柱子上,结束依次
/// 递归
///
/// 时间复杂度为O(2^n)
/// </remarks>
public static void move(string start, string middle, string end, int num)
{
if(num<=0)return;
if (num == 1)
{
Console.WriteLine("Move " + start + " To " + end);
return;
}
move(start, end, middle, num - 1);
move(start, middle,end , 1);
move(middle, start, end, num -1);
// move(start, middle, end, num-2);
// move(start,middle,end,1);
// move(middle, start,end, num - 2);
//Console.WriteLine("*************************");
//Console.WriteLine("Move " + start + " To " + middle);
//Console.WriteLine("Move " + start + " To " + end);
//Console.WriteLine("Move " + middle + " To " + end);
}