In school we just got introduced to the binary search algorithm. However, in our newest assignment we have to make the binary search do array lists. Can anyone help me modify this code to do arraylists instead of arrays?
public static Comparable[] binarySearch(Comparable[] a, int counter, Comparable b){
int left = 0;
int right = counter;
while(left <= right){
int midPoint = (left+right)/2;
if(a[midPoint].compareTo(b) == 0){
return b;
}else if(a[midPoint].compareTo(b) < 0)
left = midPoint+1;
else
right = midPoint-1;
}
}
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Collections.html#binarySearch(java.util.List,%20T,%20java.util.Comparator)