#include<stdio.h>
#define N 10
int partition(int* a,int low, int high);
void quickSort(int* a,int low,int high);
void printArray(int* a,int n);
int main(void)
{
int a[N] = {6,1,2,7,9,3,4,5,10,8};
quickSort(a,0,N-1);
// int k = partition(a,0,9);
// printf("%d\n",k);
printArray(a,N);
return 0;
}
int partition(int* a,int low, int high)
{
int temp = a[low];
while(low<high)
{
while(low<high && a[high]>=temp)
{
high--;
}
a[low] = a[high];
while(low<high && a[low]<=temp)
{
++low;
}
a[high] = a[low];
}
a[low] = temp;
return low;
}
void quickSort(int* a,int low,int high)
{
if(low>=high)
{
return ;
}
int key = partition(a,low,high);
quickSort(a,0,key-1);
quickSort(a,key+1,high);
}
void printArray(int* a,int n)
{
int i;
for(i=0;i<n;++i)
{
printf("%d\t",a[i]);
}
printf("\n");
}