Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,15 @@
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

View file

@ -0,0 +1,18 @@
function binarysearch(lst::Vector{T}, value::T, low=1, high=length(lst)) where T
if isempty(lst) return 0 end
if low ≥ high
if low > high || lst[low] != value
return 0
else
return low
end
end
mid = (low + high) ÷ 2
if lst[mid] > value
return binarysearch(lst, value, low, mid-1)
elseif lst[mid] < value
return binarysearch(lst, value, mid+1, high)
else
return mid
end
end