choose the middle value as pivot

This commit is contained in:
Ahmet Inan 2024-03-09 18:37:19 +01:00
commit eb968e50b6

View file

@ -21,6 +21,8 @@ static inline void swap(TYPE *a, int i, int j)
template <typename TYPE>
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++);