#include <stdio.h>
int BiSearch(int *p,int target,int num)
{
int pos = 0;
for(pos = 0;pos < num;pos++)
{
if(p[pos] == target)
{
return pos+1;
}
}
return 0;
}
int BiSearch_r(int *p,int target,int num)
{
int pos = 0;
for(pos = num - 1;pos >= 0;pos--)
{
if(p[pos] == target)
{
return pos+1;
}
}
return 0;
}
int BiSearch_h(int *p,int target,int low,int high)
{
int mid;
while(low <= high)
{
mid = (low+high) / 2;
// printf("%d\n",mid);
if(p[mid] == target)
{
return mid;
}
else if(p[mid] > target)
{
high = mid - 1;
}
else if(p[mid] < target)
{
low = mid + 1;
}
}
return 0;
}
void main()
{
int i[10] = {12,24,36,46,65,66,96,98,99,100};
int res = -1;
res = BiSearch_h(i,46,0,9);
printf("%d\n",res);
}