procedure swap(var x,y:integer);
var
temp:integer;
begin
temp:=x;
x:=y;
y:=temp;
end;
//冒泡排序
procedure BubbleSort(var A: array of Integer);
var
I, J, T: Integer;
begin
for I := High(A) downto Low(A) do
for J := Low(A) to High(A) - 1 do
if A[J] > A[J + 1] then
begin
swap(A[J], A[J + 1]);
T := A[J];
A[J] := A[J + 1];
A[J + 1] := T;
end;
end;
//选择排序
procedure SelectionSort(var A: array of Integer);
var
I, J, T: Integer;
begin
for I := Low(A) to High(A) - 1 do
for J := High(A) downto I + 1 do
if A[I] > A[J] then
begin
Swap(A[I], A[J]);
T := A[I];
A[I] := A[J];
A[J] := T;
if Terminated then Exit;
end;
end;
//快速排序
procedure QuickSort(var A: array of Integer);
procedure QuickSortSub(var A: array of Integer; iLo, iHi: Integer);
var
Lo, Hi, Mid, T: 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]);
T := A[Lo];
A[Lo] := A[Hi];
A[Hi] := T;
Inc(Lo);
Dec(Hi);
end;
until Lo > Hi;
if Hi > iLo then QuickSortSub(A, iLo, Hi);
if Lo < iHi then QuickSortSub(A, Lo, iHi);
end;
begin
QuickSortSub(A, Low(A), High(A));
end;