四十一:快速排序(递归)
#include"stdio.h" void Quick_sort(int *a,int begin,int end) { int middle,i,j; middle=a[begin]; i=begin; j=end; while(i<j) { while(i<j&&a[j]>=middle){ j--; a[i]=a[j]; while(i<j&&a[i<=middle]){ i++; a[j]=a[i]; } a[i]=middle; if(i-1<begin){ Quick_sort(a,begin,i-1); if(end>i+1) Quick_sort(a,i+1,end); } int main(){ int b[6]={2,3,5,9,6,4}; int t; Quick_sort(b,0,5); for(t=0;t<6;t++) printf("%d ",b[t]); return 0; }