2013-04-10 12:38:42 -07:00
|
|
|
function binarySearch (list,value)
|
|
|
|
|
local low = 1
|
|
|
|
|
local high = #list
|
|
|
|
|
while low <= high do
|
2019-09-12 10:33:56 -07:00
|
|
|
local mid = math.floor((low+high)/2)
|
2013-04-10 12:38:42 -07:00
|
|
|
if list[mid] > value then high = mid - 1
|
2019-09-12 10:33:56 -07:00
|
|
|
elseif list[mid] < value then low = mid + 1
|
|
|
|
|
else return mid
|
2013-04-10 12:38:42 -07:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
end
|