static int BinarySearch(int[] arr,int key,int low,int high)
{
low = 0;high = arr.Length - 1;
while(low<=high)
{
int mid = (low + high) / 2;
if (arr[mid] == key)
{
return mid;
}
else
{
if (arr[mid] > key)
{
high = mid - 1;
}
else
{
low = mid + 1;
}
}
}
return -1;
}
转载于:https://www.cnblogs.com/Fred1987/p/5777907.html