求教递归问题
public class HanoiY
{
void Move(char chSour, char chDest)
{
Console.WriteLine( "Move the top plate of " + chSour + "--> " + chDest);
}
void Hanoi(int n, char chA, char chB, char chC)
{
if (n == 1)
Move(chA, chC);
else
{
Hanoi(n - 1, chA, chC, chB);
this.Move(chA, chC);
Hanoi(n - 1, chB, chA, chC);
}
}
public static void Main(String[] args)
{
int n = int.Parse(Console.ReadLine());
HanoiY han = new HanoiY();
han.Hanoi(n, 'A ', 'B ', 'C ');
Console.ReadLine();
}
}
请讲解一下这个汉诺塔程序,关键是递归部分
------解决方案--------------------递归就是在条件下反复调用自己....
我觉得递归可读性不强,但是很省代码..但有人说可读性很强...?