Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ binary search

int binarySearch(arr, low, high, key) {
    if (high >= low) {
        int mid = low + (high - low) / 2; 
        if (arr[mid] == key) return mid; 
        else if (arr[mid] > key) return binarySearch(arr, low, mid - 1, key); 
        else return binarySearch(arr, mid + 1, high, key); 
    }
    return -1; 
}
Source by www.knowprogram.com #
 
PREVIOUS NEXT
Tagged: #binary #search
ADD COMMENT
Topic
Name
8+6 =