//好吧,我就用数组来实现吧
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 }
procedure compose(var arr: array of integer;
size, pos: integer);
procedure display(var arr: array of integer;
n: integer);
end;
var
Form1: TForm1;
implementation
var
arr: array [0..11] of integer =(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
{$R *.dfm}
{ TForm1 }
procedure TForm1.compose(var arr: array of integer;
size, pos: integer);
var
i, tmp: integer;
begin
if (pos + 1 = size) then
begin
display(arr, size);
Exit;
end;
for i := pos to size - 1do
begin
tmp := arr[pos];
arr[pos] := arr;
arr := tmp;
compose(arr, size, pos + 1);
tmp := arr[pos];
arr[pos] := arr;
arr := tmp;
end;
end;
procedure TForm1.display(var arr: array of integer;
n: integer);
var
i: integer;
str: string;
begin
str := '';
for i := 0 to n - 1do
begin
str := str + IntToStr(arr) + '';
end;
Memo1.Lines.Add(str);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Clear;
compose(arr, 4, 0);
//更改中间这个数字就可以了
end;
end.