这是个递归的.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure Hahaha(n: Integer;
From, Toto, Mid: Char);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
n: Integer;
begin
Memo1.Clear;
n:=StrToInt(Edit1.Text);
Hahaha(n, 'A', 'C', 'B')
end;
procedure TForm1.Hahaha(n: Integer;
From, Toto, Mid: Char);
begin
if n=1 then
Memo1.Lines.Append(IntToStr
+' From '+From+' to '+Toto)
else
begin
Hahaha(n-1, From, Mid, Toto);
Memo1.Lines.Append(IntToStr
+' From '+From+' to '+Toto);
Hahaha(n-1, Mid, Toto, From)
end
end;
end.