Skip to content

Instantly share code, notes, and snippets.

@yucombinator
Created December 15, 2014 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yucombinator/eadf61da2d5e074e9a79 to your computer and use it in GitHub Desktop.
Save yucombinator/eadf61da2d5e074e9a79 to your computer and use it in GitHub Desktop.
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