来个高手指点一下,三个柱子,盘子数定义在5个以下
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
const int COUNT = 5;
string strStart = "Pole1";
string strMiddle = "Pole2";
string strEnd = "Pole3";
HanNuo(COUNT, strStart, strMiddle, strEnd);
Console.WriteLine();
Console.ReadLine();
}
/// <summary>
/// 汉诺塔
/// </summary>
/// <param name="p_intCount">盘子数</param>
/// <param name="p_strStart">起始柱</param>
/// <param name="p_strMiddle">中间柱</param>
/// <param name="p_strEnd">目标柱</param>
static void HanNuo(int p_intCount, string p_strStart, string p_strMiddle, string p_strEnd)
{
if (p_intCount < 1)
{
return;
}
HanNuo(p_intCount - 1, p_strStart, p_strEnd, p_strMiddle);
Console.WriteLine("Move " + p_intCount.ToString() + " from " + p_strStart + " to " + p_strEnd);
HanNuo(p_intCount - 1, p_strMiddle, p_strStart, p_strEnd);
}
[此贴子已经被作者于2006-4-30 8:27:50编辑过]