Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
12
Task/Binary-search/FreeBASIC/binary-search.basic
Normal file
12
Task/Binary-search/FreeBASIC/binary-search.basic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
function binsearch( array() as integer, target as integer ) as integer
|
||||
'returns the index of the target number, or -1 if it is not in the array
|
||||
dim as uinteger lo = lbound(array), hi = ubound(array), md = (lo + hi)\2
|
||||
if array(lo) = target then return lo
|
||||
if array(hi) = target then return hi
|
||||
while lo + 1 < hi
|
||||
if array(md) = target then return md
|
||||
if array(md)<target then lo = md else hi = md
|
||||
md = (lo + hi)\2
|
||||
wend
|
||||
return -1
|
||||
end function
|
||||
Loading…
Add table
Add a link
Reference in a new issue