Skip to content

Instantly share code, notes, and snippets.

@codelance
Created December 2, 2012 01:09
Show Gist options
  • Save codelance/4186301 to your computer and use it in GitHub Desktop.
Save codelance/4186301 to your computer and use it in GitHub Desktop.
Binary Search
private static int binarySearch( int[ ] a, int toFind, int low, int high )
{
if( low > high )
return -1;
int mid = ( low + high ) / 2;
if( a[ mid ] > toFind )
return binarySearch( a, toFind, mid + 1, high );
else if( a[ mid ] < toFind )
return binarySearch( a, toFind, low, mid - 1 );
else
return mid+1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment