Skip to content

Commit fb62b95

Browse files
committed
1 parent f3a597e commit fb62b95

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

C++/chapLinearList.tex

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ \subsubsection{代码}
182182
int search(int A[], int n, int target) {
183183
int first = 0, last = n;
184184
while (first != last) {
185-
const int mid = (first + last) / 2;
185+
const int mid = first + (last - first) / 2;
186186
if (A[mid] == target)
187187
return mid;
188188
if (A[first] <= A[mid]) {
@@ -240,7 +240,7 @@ \subsubsection{代码}
240240
bool search(int A[], int n, int target) {
241241
int first = 0, last = n;
242242
while (first != last) {
243-
const int mid = (first + last) / 2;
243+
const int mid = first + (last - first) / 2;
244244
if (A[mid] == target)
245245
return true;
246246
if (A[first] < A[mid]) {

0 commit comments

Comments
 (0)