/* Date:2014.12.16
折半查找算法,也叫二分查找,用于对拥有唯一元素的查找。
需要先经过按序排序后才能进行。只对有序表适用。int BinarySearch(int *arr,int n,int x)
{
int low,mid,high;
low = 0;
high = n - 1;
while (low <= high)
{
mid =(low + high) / 2;
if (arr[mid] == x)
{
return mid;
}
else if (arr[mid] > x)
{
high = mid - 1;
}
else
{
low = mid + 1;
}
}
return -1;
}
原文地址:http://blog.csdn.net/sdgtliuwei/article/details/41969219