采用分治思想
#include <stdio.h>
#include <stdlib.h>
int partition(int s[],int low,int high){
int pivot=s[low];
while(low<high){
while(low<high&&s[high]>=pivot)--high;
s[low]=s[high];
while(low<high&&s[low]<=pivot)++low;
s[high]=s[low];
}
s[low]=pivot;
return low;
}
void quickSort(int s[],int low,int high){
if(low<high){
int pivotPos=partition(s,low,high);
quickSort(s,low,pivotPos-1);
quickSort(s,pivotPos+1,high);
}
}
int main(){
int s[]={6,5,1,9,4,1,6};
int len=sizeof(s)/sizeof(s[0]);
quickSort(s,0,len-1);
for(int i=0;i<len;++i)printf("%d ",s[i]);
return 0;
}