static const auto io_sync_off = []()
{
// turn off sync
std::ios::sync_with_stdio(false);
// untie in/out streams
std::cin.tie(nullptr);
return nullptr;
}();
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 将给定数组排序
* @param arr int整型vector 待排序的数组
* @return int整型vector
*/
int Partition(vector<int> &arr,int low,int high)
{
int pivot=arr[low];//将当前表中第一个元素设为枢纽值,对表进行划分
while(low<high)
{
while(low<high&&arr[high]>=pivot) --high;
arr[low]=arr[high]; //将比枢纽值小的元素移动到左端
while(low<high&&arr[low]<=pivot) ++low;
arr[high]=arr[low]; //将比枢纽值大的元素移动到右端
}
arr[low]=pivot; //枢纽值存放到的最终位置
return low; //返回存放枢纽值得最终位置
}
void QuickSort(vector<int> &arr,int low, int high)
{
if(low<high)
{
int pivotpos=Partition(arr,low,high); //划分
QuickSort(arr, low, pivotpos-1); //依次对左右两个子表进行递归排序
QuickSort(arr, pivotpos+1, high);
}
}
vector<int> MySort(vector<int>& arr) {
// write code here
QuickSort(arr,0,arr.size()-1);
return arr;
}
};