数组的排序
TAIntArray = array of Integer; //整型数组
procedure SortIntArray(var InArray: TAIntArray); //对整型数组排序
var
lowi, highi: Integer; //数组快速排序
procedure QuickSortArray(iLo, iHi:
Integer);
var
Lo, Hi, Mid,
value: Integer;
begin
Lo :=
iLo;
Hi :=
iHi;
Mid :=
InArray[(Lo + Hi) div 2];
repeat
while InArray[Lo] < Mid do
Inc(Lo);
while InArray[Hi] > Mid do
Dec(Hi);
if Lo <= Hi then begin
value := InArray[Hi];
InArray[Hi] := InArray[Lo];
InArray[Lo] := value;
Inc(Lo);
Dec(Hi);
end;
until Lo
> Hi;
if Hi
> iLo then
QuickSortArray(iLo, Hi);
if Lo
< iHi then
QuickSortArray(Lo, iHi);
end;
begin
lowi := Low(InArray);
highi := High(InArray);
if highi > -1 then //不为空的数组
QuickSortArray(lowi, highi);
end;
//结构体数组
TRecordNode = record
XXH:
Integer;
Sort:
Integer;
Name:string;
end;
TARecordNode = array of TRecordNode;
procedure SortNode(var ARecordNode: TARecordNode);
var
lowi, highi: Integer; //数组快速排序
procedure QuickSortArray(iLo, iHi:
Integer);
var
Lo, Hi:
Integer;
SelectedNode: TRecordNode;
begin
Lo :=
iLo;
Hi :=
iHi;
SelectedNode
:= ARecordNode[(Lo + Hi) div 2];
repeat
while ARecordNode[Lo].Sort > SelectedNode.Sort
do
Inc(Lo);
while ARecordNode[Hi].Sort < SelectedNode.Sort
do
Dec(Hi);
if Lo <= Hi then begin
SelectedNode := ARecordNode[Hi];
ARecordNode[Hi] := ARecordNode[Lo];
ARecordNode[Lo] := SelectedNode;
Inc(Lo);
Dec(Hi);
end;
until Lo
> Hi;
if Hi
> iLo then
QuickSortArray(iLo, Hi);
if Lo
< iHi then
QuickSortArray(Lo, iHi);
end;
begin
lowi := Low(ARecordNode);
highi := High(ARecordNode);
if highi > -1 then //不为空的数组