#include <iostream>
using namespace std;
#include<vector>
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 将给定数组排序
* @param arr int整型vector 待排序的数组
* @return int整型vector
*/
void quick_sort(vector<int>& arr, int l, int r) {
if (l >= r) return;
int i = l - 1;
int j = r + 1;
int x = arr[(l + r) >> 1];
while (i < j) {
do i++; while (arr[i] < x);
do j--; while (arr[j] > x);
if (i < j) swap(arr[i], arr[j]);
}
quick_sort(arr, l, j);
quick_sort(arr, j + 1, r);
}
vector<int> MySort(vector<int>& arr) {
// write code here
quick_sort(arr, 0, arr.size() - 1);
return arr;
}
};
int main()
{
class Solution s1;
vector<int> nums;
nums.push_back(5);
nums.push_back(2);
nums.push_back(3);
nums.push_back(1);
nums.push_back(4);
s1.MySort(nums);
for (int i = 0; i < nums.size(); i++)
{
cout << nums[i] << " ";
}
}
04-07
05-10
1290
07-14
573