排序数组
快速排序
class Solution { public: void quickSort(vector<int>& nums,int left ,int right) { int mid_value = nums[left + (right-left)/2] ; int i= left ; int j= right; while(i <= j) { while(nums[i] < mid_value) i++; while(nums[j] > mid_value) j--; if(i <= j) { int tmp = nums[j]; nums[j] = nums[i]; nums[i] = tmp; i++; j--; } } if(left < j) quickSort(nums,left,j); if(i < right) quickSort(nums,i,right); } vector<int> sortArray(vector<int>& nums) { quickSort(nums,0,nums.size()-1); return nums; } };