rendered paste bodypublic class test {
public static int removePerson(String person, int first, int last, String[] list) {
if (first > last) { System.out.println("Person not found"); return -1; }
else {
int mid = (first + last)/2;
int check = list[mid].compareTo(person);
if(check < 0)
return removePerson(person,mid+1,last,list);
if(check > 0)
return removePerson(person,first,mid-1,list);
else
return mid;
}
} // end removePerson
public static void main(String[] args)
{
String[] test = {"A", "B", "C", "D"} ;
System.out.println(removePerson("A", 0, 3, test)) ;
System.out.println(removePerson("B", 0, 3, test)) ;
System.out.println(removePerson("C", 0, 3, test)) ;
System.out.println(removePerson("D", 0, 3, test)) ;
}
}
/*
Output:
0
1
2
3
*/