Answers for "binary search golang"

C#
1

binary search golang

package search

// iterative version
func binarySearch(a []float64, value float64) int {
    low := 0
    high := len(a) - 1
    for low <= high {
        mid := (low + high) / 2
        if a[mid] > value {
            high = mid - 1
        } else if a[mid] < value {
            low = mid + 1
        } else {
            return mid
        }
    }
    return -1
}
Posted by: Guest on December-17-2020

C# Answers by Framework

Browse Popular Code Answers by Language