9int partition(std::vector<T>& array,
int left,
int right,
int pivotIndex) {
10 T pivotValue = array[pivotIndex];
11 std::swap(array[pivotIndex], array[right]);
12 int storeIndex = left;
13 for (
int i = left; i < right; i++) {
14 if (array[i] < pivotValue) {
15 std::swap(array[i], array[storeIndex]);
19 std::swap(array[storeIndex], array[right]);
30T
quickSelect(std::vector<T> &array,
int left,
int right,
int k){
32 int pivotIndex = (left + right) / 2;
33 int pivotNewIndex =
partition(array, left, right, pivotIndex);
34 if (pivotNewIndex == k){
36 }
else if (k < pivotNewIndex){
37 right = pivotNewIndex - 1;
39 left = pivotNewIndex + 1;