Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:无语,自己写的快排就是没有自带的快,一换qsort就过……In Reply To:无语,自己写的快排就是没有自带的快,一换qsort就过…… Posted by:allanlyy at 2008-03-04 16:05:40 > int cmp(const void* p1, const void* p2) > { > return *(int *)p1 - *(int *)p2; > } > > qsort(output, n, sizeof(int), cmp); > > 快过: > > int Partition(int low,int high) > { > int cmp; > cmp = output[low]; > while (low < high) > { > while (low < high && output[high] >= cmp) --high; > output[low] = output[high]; > while (low < high && output[low] <= cmp) ++low; > output[high] = output[low]; > } > output[low] = cmp; > return low; > } > void QSort(int low, int high) > { > int pivotloc; > if (low < high) > { > pivotloc = Partition(low, high); > QSort(low, pivotloc - 1); > QSort(pivotloc + 1, high); > } > } > > QSort(0, n - 1); Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator