Jump to content

Binary search: Difference between revisions

no edit summary
(→‎{{header|Pascal}}: The high function returns the last index. So, -1 does not need.)
No edit summary
Line 4,918:
null
]</lang>
 
=={{header|Yabasic}}==
{{trans|Lua}}
<lang Yabasic>sub floor(n)
return int(n + .5)
end sub
 
sub binarySearch(list(), value)
local low, high, mid
low = 1 : high = arraysize(list(), 1)
 
while(low <= high)
mid = floor((low + high) / 2)
if list(mid) > value then
high = mid - 1
elsif list(mid) < value then
low = mid + 1
else
return mid
end if
wend
return false
end sub
 
ITEMS = 10e6
 
dim list(ITEMS)
 
for n = 1 to ITEMS
list(n) = n
next n
 
print binarySearch(list(), 3)
print peek("millisrunning")</lang>
 
=={{header|zkl}}==
672

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.