Created
December 15, 2014 05:59
-
-
Save yucombinator/eadf61da2d5e074e9a79 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
int binarySearch(int *a, int start, int end, int value) { | |
if ((end-start) <= 1) { | |
//base case | |
return -1; | |
} | |
int cursor = start + (end - start) / 2; | |
if (a[cursor]>value) { | |
return binarySearch(a, start, cursor, value); | |
} | |
else if(a[cursor]<value) { | |
return binarySearch(a, cursor, end, value); | |
} | |
else if (a[cursor] = value) { | |
return cursor; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment