二分查找代码:

//============================================================================
// 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. sql的四大函数

    字符串函数: 1.charindex(字符串表达式 1, 字符串表达式2[,整数表达式]) select charindex('ab','BCabTabD')返回 3 select charindex ...

  2. 利用Python网络爬虫抓取微信好友的签名及其可视化展示

    前几天给大家分享了如何利用Python词云和wordart可视化工具对朋友圈数据进行可视化,利用Python网络爬虫抓取微信好友数量以及微信好友的男女比例,以及利用Python网络爬虫抓取微信好友的所 ...

  3. 【Codeforces Round #459 (Div. 2) A】Eleven

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 这个数列增长很快的. 直接暴力模拟看看是不是它的一项就好了 [代码] #include <bits/stdc++.h> ...

  4. Android应用公布后的统计——百度移动统计的应用

    一个App公布到各个渠道之后,我们须要採集不同渠道的一些信息,比方app在执行过程中产生的一些异常信息,app在各个android版本号的分布,以及各个app版本号的分布,各渠道的用户数,用户忠诚度等 ...

  5. JavaScript提高:006:ASP.NET使用easyUI TABS标签updatepanel

    前文使用了easyui的tab标签.切换问题,使用了session保存当前选中页,然后页面总体刷新时再切换至上次保存页码.那么使用updatepanel后,这个问题就非常好攻克了.http://blo ...

  6. IOS 以随意点为圆心 旋转UIView

    环绕底边中点旋转                     UIView本身是支持旋转的,能够用UIView.transform属性实现旋转. The origin of the transform i ...

  7. JAVA File类 分析(二)

    本章開始介绍UNIX文件系统. 文件系统是怎样管理文件的呢?那咱们要先文件的存储介质開始--磁盘 磁盘是计算机系统的一个硬件设备,文件系统为了可以管理磁盘.对其进行了三层抽象(本文全部内容均指UNIX ...

  8. 第一个C#控制台程序

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. 解决root登录 -bash-4.2# 的问题

  10. Nim游戏算法实现