new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
14
Task/Binary-search/Lua/binary-search-1.lua
Normal file
14
Task/Binary-search/Lua/binary-search-1.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function binarySearch (list,value)
|
||||
local low = 1
|
||||
local high = #list
|
||||
local mid = 0
|
||||
while low <= high do
|
||||
mid = math.floor((low+high)/2)
|
||||
if list[mid] > value then high = mid - 1
|
||||
else if list[mid] < value then low = mid + 1
|
||||
else return mid
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue