虽然我对理解递归没有任何问题,但我似乎无法绕过河内塔问题的递归解决方案.以下是维基百科的代码:
procedure Hanoi(n: integer; source, dest, by: char);
Begin
if (n=1) then
writeln('Move the plate from ', source, ' to ', dest)
else begin
Hanoi(n-1, source, by, dest);
writeln('Move the plate from ', source, ' to ', dest);
Hanoi(n-1, by, dest, source);
end;
End;Run Code Online (Sandbox Code Playgroud)
我理解基本情况和将问题分解成小块的概念,直到您能够移动单个磁盘.但是,我无法弄清楚非基本情况下的两个递归调用是如何协同工作的.也许有人可以帮助我?谢谢.