1
我有用於快速排列指針數組的代碼(如果可以幫助任何人),但我如何做一個doble鏈接指針列表?如何在雙鏈表的指針上實現快速排序?
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;
另請參閱此SO問題:http://stackoverflow.com/questions/1525117/whats-the-fastest-algorithm-for-sorting-a-linked-list – gabr