Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

algorithm库里的快排你一辈子也不可能写出来……

Posted by qianguize at 2009-03-04 14:33:29 on Problem 3627 and last updated at 2009-03-04 14:33:42
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator