Ejemplo n.º 1
0
static void quickSortRec(int array[], int lo, int hi)
{
	if (lo >= hi)
		return;

	int part = quickPartition(array, lo, hi);
	quickSortRec(array, lo, part - 1);				// sort left partition
	quickSortRec(array, part + 1, hi);				// sort right partition
}
Ejemplo n.º 2
0
 int kthLargestHelper(vector<int> &nums, int begin, int end, int k) {
     // terminate condition
     if (begin == end)  return nums[begin];
     int pivotIndex = quickPartition(nums, begin, end);
     int left = begin, right = end;
     if (end-pivotIndex == k-1)
         return nums[pivotIndex];
     else if (end-pivotIndex > k-1) {
         return kthLargestHelper(nums, pivotIndex+1, right, k);
     } else {
         return kthLargestHelper(nums, left, pivotIndex-1, k-(right-pivotIndex+1));
     }
 }