typedef unsigned int Uint; // ==================================================== // start:起始元素下标 // end: 结束元素下标 // ==================================================== Uint MyPartition(Uint *p,Uint start,Uint end) { Uint x,temp,j,exchange; x = *(p + end); temp = start -1; for(j = start; j < end; j++) { if(*(p+j) <= x) { temp++; exchange = *(p+j); *(p+j) = *(p+temp); *(p+temp) = exchange; } } // exchange *(p+i+1) and *(p+end) { *(p+end) = *(p+temp+1); *(p+temp+1) = x; } return (temp+1); } // ==================================================== // start:起始元素下标 // end: 结束元素下标 // ==================================================== void QuickSort(Uint *p,Uint start,Uint end) { Uint mid; if(start < end) { mid = MyPartition(p,start,end); if(start != mid) { QuickSort(p,start,mid-1); QuickSort(p,mid+1,end); } } }