cari

Rumah  >  Soal Jawab  >  teks badan

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 hari yang lalu564

membalas semua(0)saya akan balas

Tiada jawapan
  • Batalbalas