public class t5 {
public static void main(String[] args) {
int a[]= {1,2,3,4,5,6,7,8,9};
int low=0;
int hight=a.length-1;
int k=0;
int key=2;
while (hight>t5.fib(k)-1) {
k++;
}
System.out.println("k:"+fib(k));
int b[]=new int[fib(k)-1];
System.arraycopy(a, 0, b, 0, a.length);
for (int i = hight+1; i < b.length; i++) {
b[i]=a[hight];
}
int mid=0;
while (low<=hight) {
mid=low+fib(k-1)-1;
if (key<b[mid]) {
hight=mid-1;
k-=1;
}else if (key>b[mid]) {
low=mid+1;
k-=2;
}else {
if (mid<=hight) {
System.out.println("mid:"+mid);
}else {
System.out.println("hight:"+hight);
}
break;
}
}
}
public static int fib(int n) {
if (n==0) {
return 0;
}else if (n==1) {
return 1;
}
return fib(n-1)+fib(n-2);
}
}