From 2fec5af4725b1fd0c83a9d507ec2a19bc8653a80 Mon Sep 17 00:00:00 2001 From: auntyellow Date: Thu, 2 Jan 2020 11:13:36 +0800 Subject: [PATCH] fix issue #72: random pivot for array with identical values --- Utilities/Array.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Utilities/Array.cpp b/Utilities/Array.cpp index 42b8ada..94a2e7c 100644 --- a/Utilities/Array.cpp +++ b/Utilities/Array.cpp @@ -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)