#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
//基础版
int Partition(vector<int> & a, int low, int high)
{
int pivotkey = a[low ]; //把向量中的第一个值作为枢轴记录值
while (low < high)
{
while (low < high && a[high] >= pivotkey) //把比枢轴记录值小的交换到低端
high--;
swap(a[low], a[high]);
while (low < high && a[low] <= pivotkey) //把比枢轴记录值大的交换到高端
low ++;
swap(a[low], a[high]);
}
return low;
}
void QSort(vector<int> & a, int low, int high)
{
int pivot;
if (low < high)
{
pivot = Partition(a, low, high);
QSort(a, low, pivot - 1);
QSort(a, pivot + 1, high);
}
}
void QuickSort(vector<int> & a)
{
QSort(a, 0, a.size()-1);
}
int main()
{
vector<int> data = { 5,9,12,15,100,96,75,63,36 };
QuickSort(data);
for (int i = 0; i < data.size(); i++)
cout << data[i] << " ";
system("pause");
}