折半查找
来源:互联网 发布:小当家水浒卡淘宝 编辑:程序博客网 时间:2024/04/20 07:49
折半查找,数字按升序排序
public static void main(String[] args) {
int[] array = {1,2,4,6,9,11,44};
int value = 11;
int index = search(array,value);
System.out.println("value="+value+",index="+index);
}
public static int search(int[] array,int value){
int result = -1;
if(array!=null && array.length>0){
int low = 0;
int hight = array.length-1;
while(low<=hight){
int middle = (low+hight)/2;
if(array[middle]==value){
result = middle;
break;
}
else if(array[middle]<value){
low = middle+1;
}
else if(array[middle]>value){
hight = middle-1;
}
}
}
return result;
}
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 折半查找
- 数据库应用程序常见T-SQL和PL/SQL
- Dojo1.6新特性概览
- Item 13 管理在堆上new出来的对象
- ORACLE PL/SQL与SQL SERVER T-SQL一些比较【经典】
- 点通- 要相当小心
- 折半查找
- Android JNI学习之javah命令的正确使用(找了好半天才找到的,汉,网上好多说法都没用)
- 20世纪PC上的单机游戏发展历史
- 链表
- VC 双缓冲绘图
- ASP中实现java中hashMap的类
- 选择带有多个class的元素
- some Form question & answer
- 进程、线程区别(转百度知道)