Created
August 26, 2012 08:08
-
-
Save jsam/3476043 to your computer and use it in GitHub Desktop.
bin search
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
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