</pre><pre name="code" class="cpp">unsigned int BinarySearch(int array[],unsigned int len, int find_data)
{
unsigned int i = 0,start = 0, mid = 0, end = len - 1;
if ((NULL == array) || (len < 1))
{
printf("input error!!!");
return -1;
}
for(i = 0;i < len;i++)
{
f(find_data == array[i])
{
break;
}
}
if(i == len)
{
printf("the data is not in the array.error!!!");
return -1;
}
while (start <= end)
{
mid = (start + end) / 2;
if (find_data > array[mid])
{
start = mid + 1;
}
else if (find_data < array[mid])
{
end = mid - 1;
}
else
{
return mid;
}
}
}