折半查找
来源:互联网 发布:淘宝退货订单号填错 编辑:程序博客网 时间:2024/05/16 17:49
package test;
public class Search {
public class Search {
/**
* 折半查找* @param a数组,key 要查找的数,left 0(从a[0开始],right 数组长度减1(最后一个);
*/
public static boolean Searcher(int[] a,int key,int left,int right){
int middle=(left+right)/2;if(left>right){
return false;
}else{
if(key>a[middle]){
return Searcher(a,key,middle+1,right);
}else if(key<a[middle]){
return Searcher(a,key,left,middle-1);
}else{
System.out.println("在【"+(middle+1)+"】位置找到"+key);
return true;}
}
}
public static void main(String[] args) {
int a[]={12,32,1,544,6543,99,3434,1232,1241,8988,77777,2322};int left=0;int right=a.length-1;Searcher(a, 1, left, right);
}}
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- hdoj_2138How many prime numbers
- linux 指定动态库路径
- 千万千万不要运行的Linux命令
- Java中用LinkedList实现栈和队列
- MediaRecoder 框架结构
- 折半查找
- csdn 好文章
- 问心无愧的伤感爱情日志分享:我爱你,到底值不值得
- 互联网十+offer经验
- @property 属性参数的意义
- Spring2.5、Struts2、Ibatis开发框架搭建
- .Net能做什么开发
- 数据结构
- 老板给你打工