include <stdio.h>
int searchItem(int arr,int len,int key){
int low=0,high=len-1,mid;
while(low<=high){
mid=(low+high)/2;
if (key>arr[i]){
low=mid+1;
} else
if (key<arr[i]){
high=mid-1;
} else {
return mid;
}
}
return -1;
}
int main(int argc,const char*argv){
int a[]={3,4,5,7,10,20,25,26}
int loc=searchItem(a,8,20);
printf("loc = %d\n",loc);
return 0;
} |
|