c++ - In BFPRT,why “pivot” use “select” to get the median?
PHP中文网
PHP中文网 2017-04-17 15:32:56
0
0
555

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中文网

认证0级讲师

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!