Subscribe
public static int binarySearch(int[] array, int target)
{
int high = array.length, low = -1, probe;
while (high - low > 1)
{
probe = (high + low) / 2;
if (array[probe] < target)br> low = probe;
else
high = probe;
}
if (high == array.length || array[high]) != target)
return -1^high; //added the ^high
else
return high;
}
>
int insertPoint = binarySearch(selection_, index);
if (insertPoint < 0)br> myCollection.insert(~insertPoint, index);
>
You are not logged in, either login or create an account to post comments
I think the correct approach is to return -1*high, or return -1 if the array size is 0, but I keep getting inconsistencies.
posted by krunk at 9:01 AM on November 26, 2004