在有序表上进行折半查找
int BinarySearch(DataType data[], DataType kx, int n)
{
int mid;
int low = 1; //从数组的索引1开始存放元素
int high = n;
while(low <= high)
{
mid = (low + high) / 2;
if (kx == data[mid])
return mid;
else if (kx < data[mid])
high = mid -1;
else
low = mid + 1;
}
return 0;
}