快速排序
procedure QuickSort(var A: array of Integer; iLo, iHi:Integer);
procedure Swap(var A,B:Integer);
var
temp:Integer;
begin
temp:= A;
A:=B;
B:=temp;
end;
var
Lo,Hi,Mid: Integer;
begin
Lo := iLo;
Hi := iHi;
Mid := A[(Lo+ Hi) div 2];
repeat
while A[Lo]< Mid do Inc(Lo);
while A[Hi] > Mid do Dec(Hi);
if Lo <= Hi then
begin
Swap(A[Lo],A[Hi]);
Inc(Lo);
Dec(Hi);
end;
until Lo > Hi;
if Hi > iLo then QuickSort(A, iLo, Hi);
if Lo < iH then QuickSort(A, Lo, iHi);
end;
procedure Swap(var A,B:Integer);
var
temp:Integer;
begin
temp:= A;
A:=B;
B:=temp;
end;
var
Lo,Hi,Mid: Integer;
begin
Lo := iLo;
Hi := iHi;
Mid := A[(Lo+ Hi) div 2];
repeat
while A[Lo]< Mid do Inc(Lo);
while A[Hi] > Mid do Dec(Hi);
if Lo <= Hi then
begin
Swap(A[Lo],A[Hi]);
Inc(Lo);
Dec(Hi);
end;
until Lo > Hi;
if Hi > iLo then QuickSort(A, iLo, Hi);
if Lo < iH then QuickSort(A, Lo, iHi);
end;
![]()
安防 工控软件定制 QQ 2822八4536
浙公网安备 33010602011771号