#include "iostream"
//left,right为数组下标
int partition(int a[],int left,int right)
{
int i = left;
int j = right;
int temp = a[i];
while (i<j)
{
while (i<j && a[j] >= temp)//必须加等号
j--;
if (i<j)
a[i] = a[j];
while (i<j && a[i] <= temp)//必须加等号
i++;
if (i<j)
a[j] = a[i];
}
a[i] = temp;
return i;
}
void quickSort(int a[],int left,int right)
{
int dp;
if (left < right)
{
dp = partition(a,left,right);
quickSort(a,left,dp-1);
quickSort(a, dp+1,right);
}
}
int main()
{
int a[9] = { 8, 2, 6, 12, 1, 9, 5, 5, 10 };
int i;
quickSort(a, 0, 8);/*排好序的结果*/
for (i = 0; i<8; i++)
printf("%4d", a[i]);
getchar();
return 0;
}