pascle语言中,汉诺塔的递归过程到底是什么样的啊?理论我清楚,就是写不出来。帮个忙,谢谢!

来源:百度知道 编辑:UC知道 时间:2024/09/22 03:59:17
最好写出汉诺塔问题的全过程,包括主程序,谢谢

var
n:1..64;
continue:char;
i:integer;
procedure movetower(n,a,c,b:integer);
procedure movedisc(fromdisc,todisc:integer);
begin
i:=i+1;
write(fromdisc:1,'--->',todisc:1,' ');
if i mod 10=0 then
writeln;
end;
begin
if n>0 then
begin
movetower(n-1,a,b,c);
movedisc(a,c);
movetower(n-1,b,c,a);
end;
end;
begin
writeln('now let us play the game tower of hanoi');
continue:='Y';
while continue='Y' do
begin
i:=0;
writeln('how many discs are you going to move?--->');
readln(n);
writeln('the moving strp are:');
movetower(n,1,3,2);
writeln;
write('continue?(Y/N)--->);
readln(continue);
continue:=uqcase(continue);
end;
writeln('ok,goodbye!');
end.