int Find(int * A,int left,int right, int key)
{
int center;
if(left<=right)
{
center=left+(right-left)>>1;//
if(A[center]<=key)
Find(A,center+1,right,key);
else if(A[center]>key)
Find(A,left,center,key);
else
return center;
}
else
return -1;
}
int binary_find(int * A,int N,int key)
{
int left=0;
int right=N-1;
int center;
while(left<=right)
{
center=left+(right-left)>>2;
if(A[center]<=key)
left=center+1;
else if(A[center]>key)
right=center;
else
return center;
}
return -1;
}
int find(int * A,int N,int key)
{
return Find(A,0,N-1,key)
阅读(805) | 评论(0) | 转发(0) |