1 int binSearch(const int arr[],int low,int high,int key) 2 { 3 if(low>high) 4 return -1; 5 int mid=low+(high-low)/2; 6 if(arr[mid] == key) 7 return mid; 8 return (arr[mid] > key ? binSearch(arr,low,mid-1,key) : binSearch(arr,mid+1,high,key)); 9 }
1 int binSearch(const int arr[],int low,int high,int key) 2 { 3 if(low>high) 4 return -1; 5 int mid=low+(high-low)/2; 6 if(arr[mid] == key) 7 return mid; 8 return (arr[mid] > key ? binSearch(arr,low,mid-1,key) : binSearch(arr,mid+1,high,key)); 9 }