Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
365 B
2
Indexable
Never
int binarySearch(int arr[],int l,int r,int search){
    if (r >= l){
        int mid = (l + r)/2;
        if (arr[mid] == search){
            return mid;
        }
        else if (arr[mid] > search){
            return binarySearch(arr, l, mid - 1, search);
        }
        else binarySearch(arr, mid + l, r, search);
    }

    else return -1;

}