次の Quicksort proc でジョブを実行する必要があります。
//Start is the index of the first item on the list - usually 0
//Stop is the index of the last item of the list e.g. Count - 1
procedure QuickSort(var List: TStringList; Start, Stop: Integer);
var
Left: Integer;
Right: Integer;
Mid: Integer;
Pivot: integer;
Temp: integer;
begin
Left := Start;
Right := Stop;
Mid := (Start + Stop) div 2;
Pivot := StrToInt(List[mid]);
repeat
while StrToInt(List[Left]) < Pivot do Inc(Left);
while Pivot < StrToInt(List[Right]) do Dec(Right);
if Left <= Right then
begin
Temp := StrToInt(List[Left]);
List[Left] := List[Right]; // Swops the two Strings
List[Right] := IntToStr(Temp);
Inc(Left);
Dec(Right);
end;
until Left > Right;
if Start < Right then QuickSort(List, Start, Right); // Uses
if Left < Stop then QuickSort(List, Left, Stop); // Recursion
end;
呼び出す代わりに:
Files.sort;
以下を使用します。
QuickSort(Files, 0, Files.Count - 1);
1 つの注意点は、他の場合のエラー処理を追加していないため、ファイルの内容は常に有効な整数でなければならないということです。
私が使用したクイックソート機能は、Torry's Delpi にあるものを修正したものです: http://www.swissdelphicenter.ch/torry/showcode.php?id=1916