【发布时间】:2015-07-16 12:38:55
【问题描述】:
我有快速排序指针数组的代码(如果对任何人有帮助的话),但我如何为指针的双链表做到这一点?
procedure TSuperList.Sort;
begin
if Assigned(FOnCompare) and (Length(Items)>1) then
QuickSort(0,High(Items));
end;
procedure TSuperList.QuickSort(L,R:Integer);
var I,J: Integer;
P,T: Pointer;
begin
repeat
I:=L;
J:=R;
P:=Items[(L+R) shr 1];
repeat
while FOnCompare(self,Items[I],P) < 0 do Inc(I);
while FOnCompare(self,Items[J],P) > 0 do Dec(J);
if I <= J then begin
if I <> J then begin
T:=Items[I]; Items[I]:=Items[J]; Items[J]:=T;
end;
Inc(I);
Dec(J);
end;
until I > J;
if L < J then QuickSort(L,J);
L:=I;
until I >= R;
end;
【问题讨论】:
标签: delphi pointers quicksort delphi-2009