Quick Sort
unknown
c_cpp
3 years ago
564 B
1
Indexable
Never
int partition(std::vector<int>& arr, size_t start, size_t end) { int x = arr[start]; int i = start; for(size_t j = start + 1; j < end; j++) { if(arr[j]<=x) { i=i+1; std::swap(arr[i], arr[j]); } } std::swap(arr[i], arr[start]); return i; } void quick_sort(std::vector<int>& arr, size_t start, size_t end) { if(start < end) { int pivot = partition(arr, start, end); quick_sort(arr, start, pivot); quick_sort(arr, pivot + 1, end); } }