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 |
algorithm库里的快排你一辈子也不可能写出来……In Reply To:我自己写了个快排,AC了它,哈哈,再也不想用algorithm Posted by:gfedcba at 2009-03-04 14:13:10 > void Qsort(int low, int high) > { > if (low >= high) > { > return ; > } > int l, mid, r, pivot; > //mid = low +(high-low)>>1; // + -的优先级比>>还大,又一次在这里翻船了!!!! > mid = low + (high-low>>1); > Swap(arr[mid], arr[high]); > > l = low, r = high-1; > while (l<=r) > { > while (l<=r && arr[l] <= arr[high]) > { > l++; > } > while (l<=r && arr[r] >= arr[high]) > { > r--; > } > > if (l<=r) > { > Swap(arr[l], arr[r]); > l++; > r--; > } > > if (l>r) > { > pivot = l; > break; > } > } > > Swap(arr[pivot], arr[high]); > Qsort(low, pivot-1); > Qsort(pivot+1, high); > > > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator