15 lines
326 B
Text
15 lines
326 B
Text
function binarysearch(lst::Vector{T}, val::T) where T
|
|
low = 1
|
|
high = length(lst)
|
|
while low ≤ high
|
|
mid = (low + high) ÷ 2
|
|
if lst[mid] > val
|
|
high = mid - 1
|
|
elseif lst[mid] < val
|
|
low = mid + 1
|
|
else
|
|
return mid
|
|
end
|
|
end
|
|
return 0
|
|
end
|