就是放入Tstringlist內
同sort方法排序
然後再輸出到陣列
至於再返回來,沒什麼好辦法,還是保留原來沒排序之前的Stringlist吧
var
arr1:array [0..9] of integer;
s1:Tstringlist;
i:integer;
begin
arr1[0]:=6;
arr1[1]:=5;
arr1[2]:=4;
arr1[3]:=3;
arr1[4]:=2;
arr1[5]:=1;
arr1[6]:=0;
arr1[7]:=9;
arr1[8]:=7;
arr1[9]:=8;
s1:=Tstringlist.Create;
s2:=Tstringlist.Create;
for i:=0 to length(arr1)-1 do
s1.Add(inttostr(arr1[i]))
end;
s2.Text:=s1.Text;
s1.Sort;
for i:=0 to s1.Count-1 do
arr1[i]:=strtoint(s1.Strings[i]);
showmessage(inttostr(arr1[0]));
showmessage(inttostr(arr1[1]));
showmessage(inttostr(arr1[2]));
其中 s2就儲存未排序之前的資料 s2 宣告為全域性變數
就是放入Tstringlist內
同sort方法排序
然後再輸出到陣列
至於再返回來,沒什麼好辦法,還是保留原來沒排序之前的Stringlist吧
var
arr1:array [0..9] of integer;
s1:Tstringlist;
i:integer;
begin
arr1[0]:=6;
arr1[1]:=5;
arr1[2]:=4;
arr1[3]:=3;
arr1[4]:=2;
arr1[5]:=1;
arr1[6]:=0;
arr1[7]:=9;
arr1[8]:=7;
arr1[9]:=8;
s1:=Tstringlist.Create;
s2:=Tstringlist.Create;
for i:=0 to length(arr1)-1 do
begin
s1.Add(inttostr(arr1[i]))
end;
s2.Text:=s1.Text;
s1.Sort;
for i:=0 to s1.Count-1 do
begin
arr1[i]:=strtoint(s1.Strings[i]);
end;
showmessage(inttostr(arr1[0]));
showmessage(inttostr(arr1[1]));
showmessage(inttostr(arr1[2]));
end;
其中 s2就儲存未排序之前的資料 s2 宣告為全域性變數