Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

Binary Search in C

int bSearch(int arr[], int left, int right, int target) {
    if (right >= left) {
        int mid = left + (right - left) / 2;
 
        if (arr[mid] == target)
            return mid;
 
        if (arr[mid] > target)
            return binarySearch(arr, left, mid - 1, target);
 
        return binarySearch(arr, mid + 1, right, target);
    }
    return -1;
}
Source by www.interviewbit.com #
 
PREVIOUS NEXT
Tagged: #Binary #Search #C
ADD COMMENT
Topic
Name
1+6 =