Skip to content

Instantly share code, notes, and snippets.

@ccnixon
Created August 5, 2016 05:41
Show Gist options
  • Save ccnixon/4b097af01d456a37e96c69da5b1a8dbb to your computer and use it in GitHub Desktop.
Save ccnixon/4b097af01d456a37e96c69da5b1a8dbb to your computer and use it in GitHub Desktop.
binary search program in c
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