/** * ch-ibs.c * An implementation of binary search by C.H. */ int kernel(int* arr, int start, int end, int key); int ibs(int* arr, int length, int key){ //call the kernel return kernel(arr, 0, length - 1, key); } int kernel(int* arr, int start, int end, int key){ //if the target is not in the array if(start > end) return -1; int mid = (start + end) / 2; //if the mid is our key if(arr[mid] == key) return mid; //if in the first half else if(arr[mid] > key){ end = mid - 1; return kernel(arr, start, end, key); } //if in the second half else{ start = mid + 1; return kernel(arr, start, end, key); } }