From eb968e50b62a616a210832ed3c2d8ab11db3c779 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Sat, 9 Mar 2024 18:37:19 +0100 Subject: [PATCH] choose the middle value as pivot --- quick_select.hh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/quick_select.hh b/quick_select.hh index 4de523a..be7b6be 100644 --- a/quick_select.hh +++ b/quick_select.hh @@ -21,6 +21,8 @@ static inline void swap(TYPE *a, int i, int j) template static int partition(TYPE *a, int l, int h) { + int p = (l + h) / 2; + swap(a, p, h); for (int i = l; i < h; ++i) if (a[i] < a[h]) swap(a, i, l++);