Initial upload
This commit is contained in:
14
julia/binary-search/binary-search.jl
Normal file
14
julia/binary-search/binary-search.jl
Normal file
@@ -0,0 +1,14 @@
|
||||
function binarysearch(haystack, needle)
|
||||
lo, hi = 1, length(haystack)
|
||||
while lo <= hi
|
||||
idx = Int(floor((hi + lo ) / 2))
|
||||
if needle > haystack[idx]
|
||||
lo = idx + 1
|
||||
elseif needle < haystack[idx]
|
||||
hi = idx - 1
|
||||
else
|
||||
return idx:idx
|
||||
end
|
||||
end
|
||||
lo:hi
|
||||
end
|
||||
Reference in New Issue
Block a user