array1:intarr; i:integer; implementation{$R *.dfm} procedure swap(arr:intarr;i:integer;j:integer); var temp:integer; begin temp:=arr[i]; arr[i]:=arr[j]; arr[j]:=temp; end;procedure TForm1.Button1Click(Sender: TObject); procedure sort(arr:intarr;count:integer); var i,last:integer; p:pointer; c:integer; begin c:=count; if (count>1) then begin last:=0; for i:=1 to count-1 do begin if arr[i]<arr[last] then begin swap(arr,i,last); last:=last+1; end; end; //swap(arr,0,last); //sort(arr,last); //p:=@arr[last+1];//[last+1]; //sort(intarr(@p),(count-last-1)); //这里,last值会突变 if (c-1>1) then sort(arr,c-1); end; end; begin // Insert user code here setlength(array1,10); for i:=10 downto 0 do array1[i]:=10-i; sort(array1,10); for i:=low(array1) to high(array1) do ShowMessage(IntTosTR(array1[i])); end; end. 已经调试过了!也可以实现! 不知道行不行?
i:integer;
implementation{$R *.dfm}
procedure swap(arr:intarr;i:integer;j:integer);
var
temp:integer;
begin
temp:=arr[i];
arr[i]:=arr[j];
arr[j]:=temp;
end;procedure TForm1.Button1Click(Sender: TObject);
procedure sort(arr:intarr;count:integer);
var
i,last:integer;
p:pointer;
c:integer;
begin c:=count;
if (count>1) then
begin
last:=0;
for i:=1 to count-1 do
begin
if arr[i]<arr[last] then
begin
swap(arr,i,last);
last:=last+1;
end;
end;
//swap(arr,0,last);
//sort(arr,last);
//p:=@arr[last+1];//[last+1];
//sort(intarr(@p),(count-last-1)); //这里,last值会突变
if (c-1>1) then
sort(arr,c-1); end;
end;
begin
// Insert user code here
setlength(array1,10);
for i:=10 downto 0 do
array1[i]:=10-i;
sort(array1,10);
for i:=low(array1) to high(array1) do
ShowMessage(IntTosTR(array1[i]));
end;
end.
已经调试过了!也可以实现!
不知道行不行?