/Users/johnr/Desktop/IA Submissions/IA Final Submission 000307-0045 - Neil/Product/HousePointProgram_Neil/src/housepointprogram/SortingAndSearching.java |
1
2
3
4
5
6 package housepointprogram;
7
8
9
10 @author
11
12 public class SortingAndSearching {
13
14
15 public int binarySearch(Student[] studentArrayList, String studentName, int counter) {
16 int low = 0;
17 int high = counter;
18 while (low <= high) {
19 int mid = (low + high) / 2;
20 if (studentArrayList[mid].getName().compareTo(studentName) == 0) {
21 return mid;
22 } else if (studentArrayList[mid].getName().compareTo(studentName)<0) {
23 low = mid + 1;
24 } else {
25 high = mid - 1;
26 }
27 }
28 return -1;
29 }
30
31
32 }
33
34
35
36
37
38