从最初的感动开始--JAVA算法【1】--折半查找
来源:互联网 发布:阿里云大学下载 编辑:程序博客网 时间:2024/06/05 21:16
就以这个递归折半查找做开篇吧,距离上次写数据结构已然过去了10年。
希望自己不要基础上耗太久,赶紧迎头赶上吧~
public class HalfSearch { public static int halfSearch(int low,int hig,double[] list,double target){ int result_mid = -1; int mid = (low + hig)/2; if (low>hig) return result_mid; if (list[mid] < target) result_mid=halfSearch(low,mid-1,list,target); else if (list[mid] > target) result_mid=halfSearch(mid+1,hig,list,target); else if (list[mid] == target) { result_mid = mid; } return result_mid; } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here double[] list = {65,43,23,22,18,16,14,12,9,7,5,3,2,1}; double target = 77.0; int result = halfSearch(0,list.length-1,list,target); System.out.println(result); }}
0 0
- 从最初的感动开始--JAVA算法【1】--折半查找
- 从最初的感动开始--JAVA算法【3】--不简单的红黑树
- 从最初的感动开始--JAVA算法【2】--归并和快排
- 从最初的感动开始--数值计算【1】--梯度下降与牛顿法
- java折半查找算法
- 折半查找算法(开始序列有序)
- java算法之折半查找
- java算法之折半查找
- 递归的折半查找算法
- 折半查找算法的实现
- 折半查找的递归算法
- 折半查找算法的使用
- 递归的折半查找算法
- 折半查找算法的实现
- 折半查找的递归算法
- 折半查找的递归算法
- JAVA中运用数组的折半查找算法
- 数据算法之折半查找(binSearch)的Java实现
- Git branch
- Networx蓝屏问题
- [nsurl urlwithString:] 返回结果为nil
- TemperatureView:圆弧刻度温度进度条
- 微软研究院洪小文:人工智能到底是个什么东西?我们应该怎样看待它?
- 从最初的感动开始--JAVA算法【1】--折半查找
- 用vlc搭建简单流媒体服务器(UDP和TCP方式)
- Android 自定义RecyclerView 实现真正的Gallery效果
- FFmpeg基本语法
- Git stash
- Android画折线图、柱状图、饼图(使用achartengine.jar)
- 使用ImageLoader加载图片报错You should implement this support yourself (BaseImageDownloader.getStreamFrom……)
- android 6.0权限申请封装
- C#中将string转为byte[]