type
TSortCompareMethod =
function(Item1, Item2: Pointer): Integer
of object;
procedure MQuickSort(SortList: PPointerList; L, R: Integer;
SCompare: TSortCompareMethod);
var
I, J: Integer;
P, T: Pointer;
begin
repeat
I := L;
J := R;
P := SortList^[(L + R)
shr 1];
repeat
while SCompare(SortList^[I], P) < 0
do
Inc(I);
while SCompare(SortList^[J], P) > 0
do
Dec(J);
if I <= J
then
begin
if I <> J
then // kleine zusätzliche Optimierung
begin
T := SortList^[I];
SortList^[I] := SortList^[J];
SortList^[J] := T;
end;
Inc(I);
Dec(J);
end;
until I > J;
if L < J
then
MQuickSort(SortList, L, J, SCompare);
L := I;
until I >= R;
end;
procedure TMyList.Sort(Compare: TListSortCompareMethod);
begin
if (FList <>
nil)
and (Count > 0)
then
MQuickSort(FList, 0, Count - 1, Compare);
end;