二分查找算法
来源:互联网 发布:抢票软件开发 编辑:程序博客网 时间:2024/06/02 00:16
var arr = [ 2, 2, 3, 4, 8, 9, 10 ];function binSearch(arr,data) { var upperBound = arr.length - 1; var lowerBound = 0; while(lowerBound<=upperBound){//不要忘记添加循环 var mid = Math.floor((upperBound+lowerBound)/2); console.log("当前中点:"+mid) if(arr[mid]<data){ lowerBound = mid+1; }else if(arr[mid]>data){ upperBound = mid-1; }else{ return mid; } } return -1;}console.log(binSearch(arr,8));
阅读全文
0 0
- 查找算法 二分查找
- 查找算法:二分查找
- 算法--查找--二分查找
- 查找算法---二分查找
- [算法]二分查找算法
- 算法----二分查找算法
- 查找算法:二分查找算法
- [转载]查找算法----二分查找
- 查找算法之二分查找
- 查找算法之二分查找
- 查找算法_二分查找
- 算法 二分查找(折半查找)
- 查找算法之二分查找
- 查找算法之二分查找
- 查找算法之二分查找
- 查找算法之二分查找
- 查找算法之二分查找
- 查找算法之二分查找
- Verilog HDL小练习
- 11. 图--图的表示
- file 文件操作 python3
- C语言学习系列-typedef用法
- 多线程之GCD
- 二分查找算法
- MATLAB使用及介绍
- LightOJ
- 测试——搜索引擎
- 如何从Eclipse导入github上的项目源码
- C++排序算法之简单选择排序
- nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol) 错误
- 算法系列——Intersection of Two Arrays II
- 使用源码交叉构建libgcrypt库