QuickSelect Algorithm Understanding

前端 未结 6 1491
情深已故
情深已故 2020-12-04 15:58

I\'ve been poring over various tutorials and articles that discuss quicksort and quickselect, however my understanding of them is still shaky.

Given this code struct

6条回答
  •  一整个雨季
    2020-12-04 16:29

    int quickSelect(int A[], int l, int h,int k)
    {
            int p = partition(A, l, h); 
            if(p==(k-1)) return A[p];
            else if(p>(k-1)) return quickSelect(A, l, p - 1,k);  
            else return quickSelect(A, p + 1, h,k);
    
    }
    

    // partition function same as QuickSort

提交回复
热议问题