Finish the following binarySearch method to make it work for an ascending order array. The array list is the searching pool. Find target in the list, if so, return target's index in the array. Otherwise, return -1;
public static int binarySearch (int [] list, int target)
{
}
public static int binarySearch (int [] list, int target)
{
int one = 0, other = list.length - 1;
while (one <= other) {
int done = one + (other - one) / 2;
if (list[done] == target)
return done;
if (list[done] < done)
one = done + 1;
else
other = done - 1;
}
return -1;
}
// Please up vote
Get Answers For Free
Most questions answered within 1 hours.