Skip to content

Instantly share code, notes, and snippets.

@jsam
Created August 26, 2012 08:08
Show Gist options
  • Save jsam/3476043 to your computer and use it in GitHub Desktop.
Save jsam/3476043 to your computer and use it in GitHub Desktop.
bin search
bool BinSearch( float P[ ], float K, int i, int j )
{
if ( j - i <= 0 )
if ( i == j && P[ i ] == K )
return true;
else
return false;
else
{
int k = ( i + j ) / 2;
if ( P[ k ] > K )
return BinSearch( P, K, i, k - 1 );
if ( P[ k ] == K )
return true;
if ( P[ k ] < K )
return BinSearch( P, K, k + 1, j );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment