Witam
Mam prośbę o pomoc modyfikacji kodu. Jest to kod programu generującego wszystkie możliwe permutacje. np. dla liczby 2 tj. 21, 12. Poniżej w kodzie jest już podany ciąg:123456789, ale chciałbym żeby było to modyfikowane poprzez wstawienie w pole edycyjne(edit1.text) danej liczby permutacji i przez to utworzenie odpowiedniej długości łańcucha.np. dla 4 tj. 1234. Próbowałem, ale nie daję rady. Proszę o pomoc.
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
procedure P(Poz: integer; Ciag: widestring);
var
j: integer;
C: widestring;
begin
if Poz > Length(Ciag) then
listbox1.items.Add(Ciag);
for j := Poz to Length(Ciag) do
begin
C := Ciag;
C[j] := Ciag[Poz];
C[Poz] := Ciag[j];
P(Poz+1, C);
end;
end;
var
Ciag: widestring;
begin
Ciag:='123456789';
P(1, Ciag);
end;
end.