Created
May 7, 2014 17:21
-
-
Save Javex/66fc60d0a84d016e3b2c to your computer and use it in GitHub Desktop.
This file contains 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
def bsearch(items, x, L=None, R=None): | |
if L is None: | |
L = 1 | |
if R is None: | |
R = len(items) | |
if L > R: | |
return None | |
mitte = (L + R) // 2 | |
assert mitte == int(mitte) | |
if x < items[mitte-1][1]: | |
return bsearch(items, x, L, mitte-1) | |
elif x > items[mitte-1][1]: | |
return bsearch(items, x, mitte+1, R) | |
else: | |
return mitte - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment