1 #include<iostream>
 2 using namespace std;
 3 
 4 
 5 int Binary_search(int *a, int p, int r, int x)
 6 {
 7     if (p > r)
 8         return false;
 9     int midpoint = (p + r) / 2;
10     if (a[midpoint] == x)
11         return midpoint+1;
12     else if (x < a[midpoint])
13         Binary_search(a, p, midpoint - 1, x);
14     else Binary_search(a, midpoint + 1,r, x);
15 }
16 
17 
18 
19 void main()
20 {
21     int a[10];
22     for (int i = 0; i < 10; i++)
23         cin >> a[i];
24     cout<<Binary_search(a, 0, 9, 5);
25 }

 

posted on 2017-02-27 22:16  郑哲  阅读(353)  评论(0编辑  收藏  举报