1 int bnsearch(int *array,int n,int value)
2 {
3 int left=0,right=n-1;
4 while(left<=right)
5 {
6 int middle=(left+right)/2;
7 if(array[middle]==value) return middle;
8
9 else if(value<array[middle])
10 right=middle-1;
11 else left=middle+1;
12 }
13 return -1;
14 }
15 int re_bnsearch(int *array,int left,int right,int value)
16 {
17 int middle = left + ((right - left) / 2) ;
18
19 if(right<left)
20 return -1;
21 if(value<array[middle])
22 {
23 right=middle-1;
24 return re_bnsearch(array,left,right,value);
25 }
26 else if(array[middle]<value)
27 {
28 left=middle+1;
29 return re_bnsearch(array,left,right,value);
30 }
31 else return middle;
32 }