Created
June 2, 2017 13:38
-
-
Save x100ex/9380a9a7326641341dcc9872f825fbe3 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
// 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