(主要是怕自己忘记了)

一个要点,用二分时要先排序

int erfen(int arr[],int key,int n)
{
int low=0,high=n-1;
while(low<=high)
{
int mid=(low+high)/2;
if(arr[mid]<key)
{
low=mid+1;
}
if(arr[mid]==key)
{
return mid;
}
if(arr[mid]>key)
{
high=mid-1;
}
}
return -mid-1;
}