Tag: 分类

改进快速排序

如果可能,我如何改进以下快速排序(性能明智)。 有什么建议? void main() { quick(a,0,n-1); } void quick(int a[],int lower,int upper) { int loc; if(lower<upper) { loc=partition(a,lower,upper); quick(a,lower,loc-1); quick(a,loc+1,upper); } } /* Return type: int Parameters passed: Unsorted array and its lower and upper bounds */ int partition(int a[],int lower,int upper) { int pivot,i,j,temp; pivot=a[lower]; i=lower+1; j=upper; while(i<j) { while((i<upper)&&(a[i]pivot)) j–; if(ia[j]) { temp=a[j]; […]