https://en.wikipedia.org/wiki... Why not use pivot itself to get the median,just like bellow code:
int FindMidMid(int arry[], int left, int right) { if (right - left + 1 <= 5) { InsertSort(arry, left, right); return (left + right) >> 1; } int j = left - 1; for (int i = left; i <= right; i += 5) { InsertSort(arry, i, i + 4); swap(arry[++j], arry[i + 2]); } return FindMidMid(arry, left, j);
转自https://stackoverflow.com/questions/42778987/in-bfprt-why-pivot-use-select-to-get-the-median
2.1m questions
2.1m answers
62 comments
56.6k users