Skip to content

Commit

Permalink
fix issue zhedahht#72: random pivot for array with identical values
Browse files Browse the repository at this point in the history
  • Loading branch information
auntyellow committed Jan 2, 2020
1 parent 2d6eb6d commit 2fec5af
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Utilities/Array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int Partition(int data[], int length, int start, int end)
int small = start - 1;
for(index = start; index < end; ++ index)
{
if(data[index] < data[end])
if(data[index] < data[end] || (data[index] == data[end] && rand() % 2 == 0))
{
++ small;
if(small != index)
Expand Down

0 comments on commit 2fec5af

Please sign in to comment.