Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created October 19, 2010 08:50
Show Gist options
  • Select an option

  • Save oskimura/633868 to your computer and use it in GitHub Desktop.

Select an option

Save oskimura/633868 to your computer and use it in GitHub Desktop.
function binSearch(A,l,n,x)
m = l+math.floor((n-l)/2)
if A[m] == x then
return m
elseif n-l < 1 then
return false
else
tmp1 = binSearch(A,l,m,x)
if not tmp1 == false then
return tmp1
end
tmp2 = binSearch(A,m+1,n,x)
if not tmp2 == false then
return tmp2
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment