资 源 简 介
Delphi 数列的排列组合一例,演示0~N位数的任意组合,组合的数字在0~5之间,需要输入1~6整数,排列结果会显示在文本框组件中。要点代码如下:
ssList := TStringList.Create;
try
if (nBase < 1) then
begin
end
else
begin
if (sList.Count = 0) then
begin
for nIdx := 0 to num-1 do
ssList.Add(a[nIdx]);
end
else
begin
for nIdx := 0 to num-1 do
for nSidx := 0 to sList.Count-1 do
if (Pos(a[nIdx], sList.Strings[nSidx]) = 0) then
ssList.Add(a[nIdx]+sList.Strings[nSidx]);
end;
Combine(nBase-1, ssList);
end;
if ssList.Count > 0 then
begin
sList.Clear;
sList.Text := ssList.Text;sslist.Count
end;
finally
ssList.Free;
end;