1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| void quicksort(vector<int> &nums, int l ,int r) { if (l + 1 >= r) { return; } int first = l, last = r - 1, key = nums[first]; while (fisrt < last) { while (fist < last && nums[last] >= key) { --last; } nums[first] = nums[last]; while (fist < last && nums[first] <= key) { ++first; } nums[last] = nums[first]; } nums[first] = key; quicksort(nums, l, first); quicksort(nums, first + 1, r); }
|