int binarySearch (String word, Vector <String> AlphabetizedListVector){
int lefthand=0;
int righthand=AlphabetizedListVector.size() - 1;
while (lefthand <= righthand){
int mid =( lefthand + righthand ) / 2;
int cmp = word.compareToIgnoreCase(AlphabetizedListVector.ge t(mid));
if (cmp == 0) return mid;
if (cmp < 0){
righthand = mid-1;
}else{
lefthand = mid+1;
}
}
return -1;
// System.out.println("The word "+word+" does not exist.");
}
a) am i making a mistake on this?
(String word, Vector <String> AlphabetizedListVector)
? it says syntax errors on tokens regarding the parentheses and the comma, ';' expected.
b) how can I instead of 'return -1', print out that the word does not appear in the Vector? thanx