Created
August 5, 2016 05:41
-
-
Save ccnixon/4b097af01d456a37e96c69da5b1a8dbb to your computer and use it in GitHub Desktop.
binary search program in c
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 binary_search(int value, int values[], int min, int max) | |
{ | |
if (max < min) | |
{ | |
return -1; | |
} | |
int midpoint = (min + max) / 2; | |
if (values[midpoint] < value) | |
{ | |
return binary_search(value, values, midpoint + 1, max); | |
} | |
else if (values[midpoint] > value) | |
{ | |
return binary_search(value, values, min, midpoint - 1); | |
} | |
return values[midpoint]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment