折半查找法
来源:互联网 发布:拍网络电影多少钱 编辑:程序博客网 时间:2024/06/01 09:17
package com.zyf.day24;public class Zheban {public static void main(String[] args) {// TODO Auto-generated method stub int[] arr = {12,15,17,19,30}; int index = halfSearch(arr,19); System.out.println(index);}public static int halfSearch(int[] arr,int target){int max = arr.length - 1;int min = 0;int mid = (max+min)/2;while(true){if(target>arr[mid]){min = mid + 1;}else if(target<arr[mid]){max = mid - 1;}else{return mid;}//重新计算中间值mid = (min+max)/2;//找不到if(max<min){return -1;}}}}
0 0
- 折半查找法(递归)
- 折半查找法
- 汇编折半查找法
- 折半查找法
- 折半查找法
- 折半法查找
- 折半查找法
- 折半查找法
- 折半查找法C++
- 折半查找法
- JAVA折半查找法
- 折半查找法
- NSArray 折半查找法
- 折半查找法
- 折半查找法
- 折半查找法
- 折半查找法
- 算法:折半查找法
- 泛型和继承
- Minimum Window Substring
- Tomcat源码分析-线程池应用
- (翻译)draft.js 入门
- 查看程序或dll依赖的dll
- 折半查找法
- Kafka入门经典教程
- 是时候来一发DataBinding了
- 四道Java基础题 你能对几道?
- 数据链路层
- CodeForces - 451B Sort the Array 简单模拟
- pgfincore安装
- 把标准时间改成一般时间
- Kafka安装及部署