大师兄咚咚咚

二分法查找

 1 public int search(int left, int right, int searchKey) {
 2         int cur = (left + right)/2;
 3         if (ele[cur] == searchKey) {
 4             return cur;
 5         }
 6         else if (left > right) {
 7             return 0;
 8         }
 9         else {
10             if (ele[cur] < searchKey) {
11                 
12                 return search(cur +1, right, searchKey);
13             } else {
14                 return search(left, cur-1, searchKey);
15             }
16         }
17     }

未完待续!

posted on 2018-03-29 20:45  大师兄咚咚咚  阅读(96)  评论(0编辑  收藏  举报

导航