二分查找代码:

//============================================================================
// Name : BinarySearch.cpp
// Author : Danny
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================ #include <iostream>
using namespace std; int binarySearch(int a[], int left, int right, int k) {
if (left > right)
return -;
int mid = (left + right) / ;
if (a[mid] == k) {
return mid;
} else if (a[mid] > k) {
return binarySearch(a, left, mid - , k);
} else {
return binarySearch(a, mid + , right, k);
}
} int main() {
int a[] = { , , , , };
int index = binarySearch(a, , , );
cout << index << endl;
return ;
}

Binary Search Algorithm的更多相关文章

  1. [Algorithms] Binary Search Algorithm using TypeScript

    (binary search trees) which form the basis of modern databases and immutable data structures. Binary ...

  2. 【437】Binary search algorithm,二分搜索算法

    Complexity: O(log(n)) Ref: Binary search algorithm or 二分搜索算法 Ref: C 版本 while 循环 C Language scripts b ...

  3. js binary search algorithm

    js binary search algorithm js 二分查找算法 二分查找, 前置条件 存储在数组中 有序排列 理想条件: 数组是递增排列,数组中的元素互不相同; 重排 & 去重 顺序 ...

  4. [Math] Beating the binary search algorithm – interpolation search, galloping search

    From: http://blog.jobbole.com/73517/ 二分检索是查找有序数组最简单然而最有效的算法之一.现在的问题是,更复杂的算法能不能做的更好?我们先看一下其他方法. 有些情况下 ...

  5. [Algorithm] Beating the Binary Search algorithm – Interpolation Search, Galloping Search

    From: http://blog.jobbole.com/73517/ 二分检索是查找有序数组最简单然而最有效的算法之一.现在的问题是,更复杂的算法能不能做的更好?我们先看一下其他方法. 有些情况下 ...

  6. [UCSD白板题] Binary Search

    Problem Introduction In this problem, you will implemented the binary search algorithm that allows s ...

  7. Foundation: Binary Search

    /* Binary search. * * Implementation history: * 2013-10-5, Mars Fu, first version. */ /* [Binary Sea ...

  8. What's binary search?

    Binary Search: Search a sorted array by repeatedly  dividing the search interval in half. Begin with ...

  9. Binary Search - Jump on the Stones

    Binary Search algorithm. Wikipedia definition: In computer science, binary search, also known as hal ...

随机推荐

  1. 对win2012 server 虚拟机hyper-V 硬盘管理,容量变更及新增硬盘

    目的:对win2012 server 虚拟机hyper-V 硬盘管理,容量变更及新增硬盘 一.压缩虚拟机硬盘容量 进入Server 2012的操作系统,打开CMD框,输入:diskmgmt.msc,回 ...

  2. NOIP 模拟赛

    NOIP 模拟赛 思路:求 n , m 的 gcd,然后用 n , m 分别除以 gcd:若 n 或 m 为偶数,则输出 1/2. 特别的,当 n = m = 1 时,应输出 1/1 #include ...

  3. 在Docker应用场景下 如何使用新技术快速实现DevOps

    在Docker应用场景下 如何使用新技术快速实现DevOps @Container容器技术大会是由国内容器技术社区DockOne组织的专为一线开发者和运维工程师设计的顶级容器技术会议,会议强调实践和交 ...

  4. 想学android进来看看吧~ ~

    我深知学校里面有非常多同学想学习新的知识,而苦于没有指导. 事实上我想说的是,非常多东西须要靠自己,须要借助度娘,谷歌的.当然有人指导是最好的了. 对于刚接触android是不是也想做出像以下的效果: ...

  5. Vue的响应原理

    渲染render function之后就是 核心的响应式过程了 Object.defineProperty vue的核心之一就是Object.defineProperty 方法(IE9及其以上) Ob ...

  6. 使用无线局域网(WLAN)更需要注意加强安全防范

           下面链接介绍对WLAN的安全加密部分的内容,主要对WinAircrackPack工具的在Wlan方面的应用分析,介绍常见几种的加密方式,以及再使用无线设备时候的注意事项.650) thi ...

  7. noi2019模拟测试赛(四十七)

    noi2019模拟测试赛(四十七) T1与运算(and) 题意: ​ 给你一个序列\(a_i\),定义\(f_i=a_1\&a_2\&\cdots\&a_i\),求这个序列的所 ...

  8. 【Python学习】爬虫报错处理bs4.FeatureNotFound

    [BUG回顾] 在学习Python爬虫时,运Pycharm中的文件出现了这样的报错: bs4.FeatureNotFound: Couldn’t find a tree builder with th ...

  9. Java中Thread源码剖析

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 关于线程,用很长时间了,主线程下的子线程去做一些事情,就是一个代理模式,主线程分代理权给子线程,子线 ...

  10. WPF动画基础及实例

    1.介绍 在之前做winform中, 也做过一些动画效果, 但是整个动画都需要我们自己去编写, 利用计时器或线程去直接操作UI元素的属性, 然而在WPF中, 则是通过一种全新的基于属性的动画系统, 改 ...