12int partition(std::array<T, N>& array,
int left,
int right,
int pivotIndex) {
13 T pivotValue = array[pivotIndex];
14 std::swap(array[pivotIndex], array[right]);
15 int storeIndex = left;
16 for (
int i = left; i < right; i++) {
17 if (array[i] < pivotValue) {
18 std::swap(array[i], array[storeIndex]);
22 std::swap(array[storeIndex], array[right]);
33T
quickSelect(std::array<T, N> &array,
int left,
int right,
int k){
35 int pivotIndex = (left + right) / 2;
36 int pivotNewIndex =
partition(array, left, right, pivotIndex);
37 if (pivotNewIndex == k){
39 }
else if (k < pivotNewIndex){
40 right = pivotNewIndex - 1;
42 left = pivotNewIndex + 1;