Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

binary search c++

int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
Source by www.google.com #
 
PREVIOUS NEXT
Tagged: #binary #search
ADD COMMENT
Topic
Name
2+7 =