#include <iostream>
#include <vector>
using namespace std;
void swap(int& a, int& b) {
int temp = a;
a = b;
b = temp;
}
int partition(vector<int>& arr, int low, int high) {
int pivot = arr[high];
int smallRightBound = low - 1;
for (int i = low; i < high; ++i)
{
if (arr[i] < pivot)
{
++smallRightBound;
swap(arr[smallRightBound], arr[i]);
}
}
swap(arr[smallRightBound + 1], arr[high]);
return smallRightBound + 1;
}
void quickSort(vector<int>& arr, int low, int high) {
if (low < high)
{
int pivot = partition(arr, low, high);
quickSort(arr, pivot + 1, high);
quickSort(arr, low, pivot - 1);
}
}
void quickSort(vector<int>& arr) {
int size = arr.size();
quickSort(arr, 0, size - 1);
}
int main() {
vector<int> arr = { 7, 2, 1, 6, 8, 5, 3, 4 };
quickSort(arr);
cout << "排序结果:";
for (int num : arr) {
cout << num << " ";
}
cout << endl;
return 0;
}