int bin_search(int* a, int key)
{
int lo = 0;
int hi = sizeof(a)/sizeof(int) - 1;
while(lo <=hi)
{
int mid = (lo + hi)/2;
if(key < a[mid]) { hi = mid - 1;}
else if (key > a[mid]) { lo = mid + 1;}
else return mid;
}
return -1;
}
....
for(i = 0; i < sz; ++i)
{
printf("%d\n", bin_search(a, i));
}
I think that I have a problem with this, but I can't understand why:
int hi = sizeof(a)/sizeof(int) - 1;