Binary search to learn

1, title

The array has a shaping element 10 a, and by value in ascending order. Enter an integer x, then look for x in the array, if found, the corresponding output index, otherwise, output "Not Found".
Premise binary search method: find a given number in a strictly increasing sequence in X.

2, thinking

Initialize the pointer at the beginning and end of the array, and then obtain an intermediate number, comparing, moving the head and tail pointers, for half of the trade-offs. When found mid> low, then the right side of a certain minimum number of mid when mid <high, a certain minimum number of the left side of the mid (or mid).

3, insufficient learning / dichotomy major difficulties encountered:

(1) analysis of the subject is difficult, I do not know where to start point.
(2) No notice is orderly or disorderly, forget ordering.
(3) an array overflow, resulting in compilation error.
(4) two divided to feel it is still very difficult to be more analysis to answer.

4, a flowchart

5, part of the code

Guess you like

Origin www.cnblogs.com/zyr-DR/p/12052143.html