//写法一
class Resulotion{
public:
void quickSort(vector<int> &arr, int left, int right){
if (left >= right) return;
int p = partition(arr, left, right);
quickSort(arr, left, p - 1);
quickSort(arr, p + 1, right);
}
int partition(vector<int> &arr, int left, int right){
int e = arr[left];
//element: [left+1, j]<v [j+1, i]>v
int j = left, i = left + 1;
for (i; i <= right; i++){
if (arr[i] < e)
swap(arr[++j], arr[i]);
}
swap(arr[left], arr[j]);
return j;
}
};
//写法二
int partition(vector<int> &arr, int left, int right){
int v = arr[left];
//[left+1,j] < v, v < [j+1, i]
int j = left;
for (int i = left + 1; i <= right; i++){
if (arr[i] < v)
swap(arr[++j], arr[i]);
}
swap(arr[left], arr[j]);
return j;
}
void _quickSort(vector<int> &arr, int left, int right){
if (left >= right) return;
int p = partition(arr, left, right);
_quickSort(arr, left, p - 1);
_quickSort(arr, p + 1, right);
}
void quickSort(vector<int> &arr){
_quickSort(arr, 0, arr.size() - 1);
}