Skip to content

Commit 353123f

Browse files
committed
read through ch12
1 parent 19511bb commit 353123f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

ch12/Search.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public static int binarySearch(Card[] cards, Card target) {
2424
while (low <= high) {
2525
System.out.println(low + ", " + high);
2626

27-
int mid = (low + high) / 2; // step 1
27+
int mid = (low + high) / 2; // step 1
2828
int comp = cards[mid].compareTo(target);
2929

30-
if (comp == 0) { // step 2
30+
if (comp == 0) { // step 2
3131
return mid;
32-
} else if (comp < 0) { // step 3
32+
} else if (comp < 0) { // step 3
3333
low = mid + 1;
34-
} else { // step 4
34+
} else { // step 4
3535
high = mid - 1;
3636
}
3737
}
@@ -48,14 +48,14 @@ public static int binarySearchRec(Card[] cards, Card target,
4848
if (high < low) {
4949
return -1;
5050
}
51-
int mid = (low + high) / 2; // step 1
51+
int mid = (low + high) / 2; // step 1
5252
int comp = cards[mid].compareTo(target);
5353

54-
if (comp == 0) { // step 2
54+
if (comp == 0) { // step 2
5555
return mid;
56-
} else if (comp < 0) { // step 3
56+
} else if (comp < 0) { // step 3
5757
return binarySearchRec(cards, target, mid + 1, high);
58-
} else { // step 4
58+
} else { // step 4
5959
return binarySearchRec(cards, target, low, mid - 1);
6060
}
6161
}

0 commit comments

Comments
 (0)