1 #include <stdio.h> 2 3 int main(void) 4 { 5 int a[6] = {2,1,0,5,4,3}; 6 int i; 7 QuickSort(a,0,5);//第二个参数表示第一个元素的下标 第三个参数表示最后的元素的下标 8 9 for(i= 0 ;i<6;++i) 10 printf("%d",a[i]); 11 printf("\n"); 12 return 0; 13 } 14 15 void QuickSort(int *a , int low ,int high) 16 { 17 int pos; 18 if(low<high) 19 { 20 pos = FindPos(a,low,high); 21 QuickSort(a,low,pos-1); 22 QuickSort(a,pos+1,high); 23 } 24 } 25 26 int FindPos(int *a , int low , int high) 27 { 28 int val = a[low]; 29 while(low<high) 30 { 31 while(low<high && a[high]>=val ) 32 --high; 33 a[low] = a[high]; 34 while(low<high && a[low]<=val ) 35 ++low; 36 a[high] = a[low]; 37 }//终止while循环之后low和high 一定是相等的 38 a[low] = val; 39 40 return low;//low也可以为high 41 }