求助贴,关于Java递归二分法
1个回答
展开全部
public class TwoTest {
public static void main(String[] args) {
int[] a = {1,2,3,5,9,11,45,55,95,100,198,201,202,333};
System.out.println(search(a,100,0,a.length));
}
public static int search(int[] a,int key,int star,int end){
if(star > end)
return -1;
int mid = (star+end)/2;
if(a[mid] == key)
return mid;
if(a[mid]<key)
return(search(a,key,mid+1,end));
return(search(a,key,star,mid-1));
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询