#include <bits/stdc++.h>
using namespace std;
int partition(vector<int>& arr, int low, int high) {
int pivot = arr[high];
int i = low - 1;
for (int j = low; j <= high - 1; j++) {
if (arr[j] < pivot) {
i++;
swap(arr[i], arr[j]);
}
}
swap(arr[i + 1], arr[high]);
return i + 1;
}
void quickSort(vector<int>& arr, int low, int high) {
if (low < high) {
int pi = partition(arr, low, high);
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
int main() {
vector<int> arr = {10, 7, 8, 9, 1, 5};
int n = arr.size();
clock_t begin = clock();
quickSort(arr, 0, n - 1);
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << "\n";
clock_t end = clock();
cout<<"Time run: "<<(float)(end-begin)/CLOCKS_PER_SEC<<" s"<<endl;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBwYXJ0aXRpb24odmVjdG9yPGludD4mIGFyciwgaW50IGxvdywgaW50IGhpZ2gpIHsKICAgIGludCBwaXZvdCA9IGFycltoaWdoXTsKICAgIGludCBpID0gbG93IC0gMTsKICAgIGZvciAoaW50IGogPSBsb3c7IGogPD0gaGlnaCAtIDE7IGorKykgewogICAgICAgIGlmIChhcnJbal0gPCBwaXZvdCkgewogICAgICAgICAgICBpKys7CiAgICAgICAgICAgIHN3YXAoYXJyW2ldLCBhcnJbal0pOwogICAgICAgIH0KICAgIH0KICAgIHN3YXAoYXJyW2kgKyAxXSwgYXJyW2hpZ2hdKTsgIAogICAgcmV0dXJuIGkgKyAxOwp9Cgp2b2lkIHF1aWNrU29ydCh2ZWN0b3I8aW50PiYgYXJyLCBpbnQgbG93LCBpbnQgaGlnaCkgewogICAgaWYgKGxvdyA8IGhpZ2gpIHsKICAgICAgICBpbnQgcGkgPSBwYXJ0aXRpb24oYXJyLCBsb3csIGhpZ2gpOwogICAgICAgIHF1aWNrU29ydChhcnIsIGxvdywgcGkgLSAxKTsKICAgICAgICBxdWlja1NvcnQ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