📄 unit1.~pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure towers(n:integer;fromPeg:char;toPeg:char;auxPeg:char);
begin if n=1 then // /*递归出口*/ form1.memo1.Lines.Add('移动 1 号盘 从柱子 '+fromPeg+' 到柱子 '+toPeg) else begin // 把n-1个圆盘从fromPeg借助toPeg移至auxPeg*/ towers(n-1,fromPeg,auxPeg,toPeg); // /*把圆盘n由fromPeg直接移至toPeg*/ form1.memo1.Lines.Add('移动 '+inttostr(n)+' 号盘 从柱子 '+fromPeg+' 到柱子 '+toPeg); // 把n-1个圆盘从auxPeg借助fromPeg移至toPeg*/ towers(n-1,auxPeg,toPeg,fromPeg); end;end;procedure TForm1.Button1Click(Sender: TObject);
begin
towers(4,'A', 'C', 'B');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -