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 610c078
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Utilities/Array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Distributed under the BSD license.
*******************************************************************/

//==================================================================
// ¡¶½£Ö¸Offer¡ª¡ªÃûÆóÃæÊÔ¹Ù¾«½²µäÐͱà³ÌÌâ¡·´úÂë
// ×÷ÕߣººÎº£ÌÎ
// ����ָOffer�����������Թپ������ͱ���⡷����
// ���ߣ��κ���
//==================================================================

#include <stdlib.h>
Expand Down 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 610c078

Please sign in to comment.