#include <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
int GetPivot(std::vector<int>& nums, int low, int high)
{
int pivot = nums[low];
while (low < high) {
while (low < high && nums[high] >= pivot) --high;
nums[low] = nums[high];
while (low < high && nums[low] <= pivot) ++low;
nums[high] = nums[low];
}
nums[low] = pivot;
return low;
}
void QuickSort(std::vector<int>& nums, int low, int high)
{
if (low < high) {
int pivot = GetPivot(nums, low, high);
QuickSort(nums, low, pivot - 1);
QuickSort(nums, pivot + 1, high);
}
}
int main()
{
std::vector<int> nums{10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
QuickSort(nums, 0, nums.size() - 1);
std::copy(nums.begin(), nums.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
}