Created
October 19, 2010 08:50
-
-
Save oskimura/633868 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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