递归二分法
public class ttt {
public static int[] ii = new int[]{1,2,3,4,5,6,7,8,9,10,11};
public static int start = 0;
public static int end = 0;
public static int middle = 0;
String n = "";
public void twoF(int aa,int m){
n += (m+1+"-");
if(aa!=ii[m]){
if(ii[m]>aa){
end = m;
m = (start+end)/2;
}
if(ii[m]<aa){
start = m;
m = (start+end)/2;
}
twoF(aa,m);
}else{
System.out.println(n);
}
}
public static void main(String[] args) {
start = 0;
end = ii.length;
middle = (start+end)/2;
new ttt().twoF(11,middle);
}
}
写个自己看的明白的。。。。