using namespace std;
void quick_sort(int unsorted[], int nleft, int nright)
{
if (nleft < nright)
{
int pivot = unsorted[(nleft + nright) / 2]; //此处选择数组中间值
int i = nleft-1, j = nright+1;
while (i<j)
{
do
{
++i;
} while (unsorted[i]<pivot);
do
{
--j;
} while (unsorted[j]>pivot);
if (i<j)
{
swap(unsorted[i], unsorted[j]);
}
}
quick_sort(unsorted, nleft, i-1);
quick_sort(unsorted, j+1, nright);
}
}
int main(int argc, char **argv)
{
int x[] = { 3,3,3,0,0,0,9,10,11,6, 7, 8, 2, 4, 1, 5, 0 };
quick_sort(x, 0, sizeof(x) / 4-1);
for (int i = 0; i < sizeof(x) / 4; i++)
{
cout << x[i] << endl;
}
return 0;
}