import java.util.*;
public class Searcher<T> {
// Returns the index of the key in the sorted array, or -1 if the
// key is not found.
public static <T> int binarySearch(T[] array, int arraySize, T key,
Comparator<T> comparer) {
int lowBound = 0;
int highBound = arraySize - 1;
int mid = 0;
//string this.key = key;
while (highBound > lowBound) {
mid = (highBound - lowBound) / 2;
String results = comparer.compare(array[mid], key.toString());
if(results > key){
lowBound = mid + 1;
}
else if(results > key) {
highBound = mid - 1;
}
else { return mid;
}
}
return -1;
}
}
when i run the program I get this error:
Searcher.java:17: error: bad operand types for binary operator '<'
if(results < key){
^
first type: int
second type: T
where T is a type-variable:
For both lines 17 and 20. i cannot for the life of me figure out how to compare the results from line 15 to the key i am searching for in my binary search algorithm.][2]