[Delphi (Object Pascal)] Delphi对字符串列表进行快速排序 →→→→→进入此内容的聊天室

来自 , 2020-10-19, 写在 Delphi (Object Pascal), 查看 201 次.
URL http://www.code666.cn/view/f78688fb
  1. procedure QuickSort(const AList: TStrings; const AStart, AEnd: Integer);
  2.   procedure Swap(const AIdx1, AIdx2: Integer);
  3.   var
  4.     Tmp: string;
  5.   begin
  6.     Tmp := AList[AIdx1];
  7.     AList[AIdx1] := AList[AIdx2];
  8.     AList[AIdx2] := Tmp;
  9.   end;
  10.  
  11. var
  12.   Left: Integer;
  13.   Pivot: string;
  14.   Right: Integer;
  15. begin
  16.   if AStart >= AEnd then
  17.     Exit;
  18.   Pivot := AList[AStart];
  19.   Left := AStart + 1;
  20.   Right := AEnd;
  21.   while Left < Right do
  22.     begin
  23.       if AList[Left] < Pivot then
  24.         Inc(Left)
  25.       else
  26.         begin
  27.           Swap(Left, Right);
  28.           Dec(Right);
  29.         end;
  30.     end;
  31.   Dec(Left);
  32.   Swap(Left, AStart);
  33.   Dec(Left);
  34.   QuickSort(AList, AStart, Left);
  35.   QuickSort(AList, Right, AEnd);
  36. end;
  37. //delphi/4526

回复 "Delphi对字符串列表进行快速排序"

这儿你可以回复上面这条便签

captcha