快速排序
来源:互联网 发布:什么手机网络信号最好 编辑:程序博客网 时间:2024/06/06 03:16
int quickSort(int *array,int beg,int end){ if(beg<end){ int index=portSort(array,beg,end); printf("index:%d\n",index); quickSort(array,beg,index-1); quickSort(array,index+1,end); }}int portSort(int *array,int beg,int end){ int i=beg,j=end; int val=array[beg++]; while(beg<end) { while(beg<end && array[beg]<=val)beg++; while(beg<end && array[end]>=val)end--; if(beg<end)swap(array[beg],array[end]); } swap(array[i],array[beg-1]); for(int i=0;i<sizeof(array)/4;i++) { printf("%d,",array[i]); } printf("\n"); return end;}