View Single Post
Old 03-28-2006, 05:17 PM   #8 (permalink)
Benito Fireslinger
Registered User
 
Join Date: Feb 2002
Location: Georgia
Posts: 333
+0 Internets
this is it in java... but same concept

Code:
public static int binarySearch( Comparable [ ] a, Comparable x ) { int low = 0; int high = a.length - 1; int mid; while( low <= high ) { mid = ( low + high ) / 2; if( a[ mid ].compareTo( x ) < 0 ) low = mid + 1; else if( a[ mid ].compareTo( x ) > 0 ) high = mid - 1; else return mid; } return NOT_FOUND; // NOT_FOUND = -1 }
__________________
Archimonde
Benito Fireslinger is offline   Reply With Quote

 
Uberguilds Network