mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-07 19:49:24 +01:00
* fixed bug in QuickSort_ItemList_CustomItemExchanger_Context and
QuickSort_ItemList_Context and which can cause wrong sort results, due to not taking into account that the pivot can be moved by the swap operation git-svn-id: trunk@41191 -
This commit is contained in:
parent
79b82acfcc
commit
ea340b9481
@ -182,10 +182,17 @@ var
|
|||||||
while Comparer(P, Items + ItemSize*J, Context) < 0 do
|
while Comparer(P, Items + ItemSize*J, Context) < 0 do
|
||||||
Dec(J);
|
Dec(J);
|
||||||
If I <= J then
|
If I <= J then
|
||||||
|
begin
|
||||||
|
if I < J then
|
||||||
begin
|
begin
|
||||||
Move((Items + ItemSize*I)^, TempBuf^, ItemSize);
|
Move((Items + ItemSize*I)^, TempBuf^, ItemSize);
|
||||||
Move((Items + ItemSize*J)^, (Items + ItemSize*I)^, ItemSize);
|
Move((Items + ItemSize*J)^, (Items + ItemSize*I)^, ItemSize);
|
||||||
Move(TempBuf^, (Items + ItemSize*J)^, ItemSize);
|
Move(TempBuf^, (Items + ItemSize*J)^, ItemSize);
|
||||||
|
if P = (Items + ItemSize*I) then
|
||||||
|
P := Items + ItemSize*J
|
||||||
|
else if P = (Items + ItemSize*J) then
|
||||||
|
P := Items + ItemSize*I;
|
||||||
|
end;
|
||||||
Inc(I);
|
Inc(I);
|
||||||
Dec(J);
|
Dec(J);
|
||||||
end;
|
end;
|
||||||
@ -238,8 +245,15 @@ procedure QuickSort_ItemList_CustomItemExchanger_Context(
|
|||||||
while Comparer(P, Items + ItemSize*J, Context) < 0 do
|
while Comparer(P, Items + ItemSize*J, Context) < 0 do
|
||||||
Dec(J);
|
Dec(J);
|
||||||
If I <= J then
|
If I <= J then
|
||||||
|
begin
|
||||||
|
if I < J then
|
||||||
begin
|
begin
|
||||||
Exchanger(Items + ItemSize*I, Items + ItemSize*J, Context);
|
Exchanger(Items + ItemSize*I, Items + ItemSize*J, Context);
|
||||||
|
if P = (Items + ItemSize*I) then
|
||||||
|
P := Items + ItemSize*J
|
||||||
|
else if P = (Items + ItemSize*J) then
|
||||||
|
P := Items + ItemSize*I;
|
||||||
|
end;
|
||||||
Inc(I);
|
Inc(I);
|
||||||
Dec(J);
|
Dec(J);
|
||||||
end;
|
end;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user