June 2017
Beginner
1296 pages
69h 23m
English
... } 23 System.out.println(" * "); // indicate current middle
24
25 // if the element is found at the middle
26 if (key == data[middle]) {
27 location = middle; // location is the current middle
28 }
29 else if (key < data[middle]) { // middle element is too high
30 high = middle - 1; // eliminate the higher half
31 }
32 else { // middle element is too low
33 low = middle + 1; // eliminate the lower half
34 }
35
36 middle = (low + high + 1) / 2; // recalculate the middle
37 } while ((low <= high) && (location == -1));
38
39 return location; // return location of search key
40 }
41
42 // method to output certain values in array
43 private static String remainingElements(
44 int[] data, int low, int high) {
45 StringBuilder temporary = new StringBuilder(); ...