I wonder if the author is aware of antiqsort<p><a href="https://www.cs.dartmouth.edu/~doug/aqsort.c" rel="nofollow">https://www.cs.dartmouth.edu/~doug/aqsort.c</a>
and
<a href="https://github.com/matslina/qsort/blob/master/antiqsort.c" rel="nofollow">https://github.com/matslina/qsort/blob/master/antiqsort.c</a>
...
The textbook solution is to use this pivot selection algorithm:<p><a href="https://en.wikipedia.org/wiki/Median_of_medians" rel="nofollow">https://en.wikipedia.org/wiki/Median_of_medians</a><p>In practice it is not really worth it.