16 int high = nelems - 1;
22 if (high == low + 1) {
23 if (arr[low] > arr[high])
24 ELEM_SWAP<T>(arr[low], arr[high]);
29 int middle = (low + high) / 2;
30 if (arr[middle] > arr[high]) ELEM_SWAP<T>(arr[middle], arr[high]);
31 if (arr[low] > arr[high]) ELEM_SWAP<T>(arr[low], arr[high]);
32 if (arr[middle] > arr[low]) ELEM_SWAP<T>(arr[middle], arr[low]);
35 ELEM_SWAP<T>(arr[middle], arr[low+1]);
42 while (arr[low] > arr[ll])
46 while (arr[hh] > arr[low])
52 ELEM_SWAP<T>(arr[ll], arr[hh]);
56 ELEM_SWAP<T>(arr[low], arr[hh]);
69 return quick_select<T>(arr, nelems, (nelems - 1) / 2);
T quick_select_median(T *arr, int nelems)
void ELEM_SWAP(T &a, T &b)
T quick_select(T *arr, int nelems, int select)