一个简单的二分查找实现
来源:互联网 发布:百合网网站源码 编辑:程序博客网 时间:2024/06/05 04:40
第一次写博客,感觉要写的东西有很多,以前写的东西都在印象笔记里面,东西很杂乱,我需要慢慢的的整理出来。我就从最简单的开始整理吧~一个简单的二分查找算法。
- public class BinarySearch
- {
- public static int binary_search(int[] array, int value)
- {
- int beginIndex = 0;// 低位下标
- int endIndex = array.length - 1;
- int midIndex = -1;
- while (beginIndex <= endIndex) {
- midIndex = beginIndex + (endIndex - beginIndex) / 2;
- if (value == array[midIndex]) {
- return midIndex;
- } else if (value < array[midIndex]) {
- endIndex = midIndex - 1;
- } else {
- beginIndex = midIndex + 1;
- }
- }
- return -1;
- }
- public static void main(String[] args)
- {
- System.out.println("Start...");
- int[] myArray = new int[] { 1, 2, 3, 5, 6, 7, 8, 9 };
- System.out.println("查找数字8的下标:");
- System.out.println(binary_search(myArray, 8));
- }
- }
0 0
- 一个简单的二分查找实现
- 二分查找的简单实现.
- 二分查找的简单实现
- 一个简单的二分查找代码片
- 用php实现简单的二分查找
- 二分查找算法的简单实现
- 简单的二分查找
- Java实现一个二分查找
- 二分查找,要注意的地方--写一个正确的二分查找,并不简单
- 二分查找的实现
- 二分查找的实现
- 二分查找的实现
- 二分查找的实现
- 二分查找的实现
- 二分查找的实现
- 二分查找的实现
- 二分查找的实现
- 二分查找的实现
- 论“产品经理”这条路——TSY
- [Lua基础]包package——模块开发
- json数据转换异常:net.sf.json.JSONException: java.lang.reflect.InvocationTargetException
- CoreSeek 安装问题解决及使用
- hdu 2149 Public Sale 基础博弈
- 一个简单的二分查找实现
- [小技巧] 使用zipinfo判断 zip 包的文件信息
- 数据挖掘 应用案例集
- 解读Hashtable
- Win7 在安装vs2010后向sql2008添加SQL_Server_Management详解
- U3D平台SDK接入的一些经验总结
- Comparison of business integration software
- [翻译] Hazelcast Clustering Plugin 部署指南(未完待续)
- 寻找数组中无序的部分,并返回索引。