public static int binSearch (double[] list, double item)
{
int bottom = 0;
int top = list.length - 1;
int middle;
boolean found = false;
int location = -1;
while (bottom <= top && !found)
{
middle = (bottom + top)/2;
if (list[middle] == item)
{
found = true;
location = middle;
}
else if (list[middle] < item)
bottom = middle +1;
else
top = middle -1;
}
for (int i = location; i >= 0 && list[i] == item; i--)
location = i;
return location;
}
|