搜尋

首頁  >  問答  >  主體

c++ - In BFPRT,why “pivot” use “select” to get the median?

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

PHP中文网PHP中文网2772 天前563

全部回覆(0)我來回復

無回覆
  • 取消回覆