Skip to content

Instantly share code, notes, and snippets.

@x100ex
Created June 2, 2017 13:38
Show Gist options
  • Save x100ex/9380a9a7326641341dcc9872f825fbe3 to your computer and use it in GitHub Desktop.
Save x100ex/9380a9a7326641341dcc9872f825fbe3 to your computer and use it in GitHub Desktop.
// https://schani.wordpress.com/2010/04/30/linear-vs-binary-search/
static int
binary (const int *arr, int n, int key) {
int min = 0, max = n;
while (min < max) {
int middle = (min + max) >> 1;
if (key > arr [middle])
min = middle + 1;
else
max = middle;
}
return min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment