I have to do a recursive binary search, and this is what I have:

Am I on the right track?Quote:

// recursive version of binarySearch

public static Comparable binarySearchRecursive(int first, int last,

Comparable[] data,

Comparable target)

{

if (first < last)

{

int mid = first + (last - first) / 2;

if (data[mid].compareTo(target) < 0)

{

return binarySearchRecursive(mid + 1, last, data, target);

}

else if (data[mid].compareTo(target) > 0)

{

return binarySearchRecursive(mid - 1, last, data, target);

}

else

{

return mid;

}

}

return -(first + 1);

}

}