lower_bound()upper_bound() 是方便的在有序数组中二分查找的函数,并且在STL其他数据结构中也提供该方法(如mapset)。
但是两函数并不是二分查找“小于”和“大于”的第一个元素。
lower_bound(first, last, val)大于等于val的第一个元素
upper_bound(first, last, val)严格大于val的第一个元素

lower_bound()

lower_bound - C++ Reference

Returns an iterator pointing to the first element in the range [first,last) which does not compare less than val.

not compare less than 不小于

upper_bound()

upper_bound - C++ Reference

Returns an iterator pointing to the first element in the range [first,last) which compares greater than val.

compares greater than 大于

lower_bound()和upper_bound()的更多相关文章

  1. STL源码学习----lower_bound和upper_bound算法

    转自:http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html 先贴一下自己的二分代码: #include <cstdio&g ...

  2. [STL] lower_bound和upper_bound

    STL中的每个算法都非常精妙, ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一 ...

  3. vector的插入、lower_bound、upper_bound、equal_range实例

    对于这几个函数的一些实例以便于理解: #include <cstdlib> #include <cstdio> #include <cstring> #includ ...

  4. STL中的lower_bound和upper_bound的理解

    STL迭代器表述范围的时候,习惯用[a, b),所以lower_bound表示的是第一个不小于给定元素的位置 upper_bound表示的是第一个大于给定元素的位置. 譬如,值val在容器内的时候,从 ...

  5. STL 源码分析《5》---- lower_bound and upper_bound 详解

    在 STL 库中,关于二分搜索实现了4个函数. bool binary_search (ForwardIterator beg, ForwardIterator end, const T& v ...

  6. lower_bound和upper_bound算法

    参考:http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html ForwardIter lower_bound(ForwardIte ...

  7. lower_bound 和 upper_bound

    Return iterator to lower bound Returns an iterator pointing to the first element in the range [first ...

  8. STL源码学习----lower_bound和upper_bound算法[转]

    STL中的每个算法都非常精妙,接下来的几天我想集中学习一下STL中的算法. ForwardIter lower_bound(ForwardIter first, ForwardIter last,co ...

  9. [转] STL源码学习----lower_bound和upper_bound算法

    http://www.cnblogs.com/cobbliu/archive/2012/05/21/2512249.html PS: lower_bound of value 就是最后一个 < ...

  10. STL algorithm算法lower_bound和upper_bound(31)

    lower_bound原型: function template <algorithm> std::lower_bound default (1) template <class F ...

随机推荐

  1. 【转】Why BIOS loads MBR into 0x7C00 in x86 ?

    最近在读Linux的grub的stage1中看到“BIOS执行INT 0x19,加载MBR内容至0x7c00,然后跳转执行”,为什么一定是0x7c00这个地址. 作者刚好在下面推荐了这篇文件,刚好顺手 ...

  2. org.apache.subversion.javahl.ClientException: svn: E155004: "" run 'svn cleanup' first.

    原文:https://blog.csdn.net/Duqian94/article/details/53791250 解决方法:1.在eclipse中右键项目“team-->refresh/cl ...

  3. Linux(Centos7.6)下安装Gitlab详细教程

    Gitlab搭建操作步骤: 1.查看Linux系统版本确认gitlab需要使用的安装包类型 使用命令:cat /etc/redhat-release CentOS Linux release 7.6. ...

  4. wordpress中文目录出现“有点尴尬诶!该页无法显示"

    原因不详,可能是.htaccess.网上说删除后再更新固定链接会再生成,但是我没有.我又把原来的.htaccess上传后更改固定链接为“数字型”,测试后可以正常浏览. 然后又再更改为原来的“日期和名称 ...

  5. V4L2视频采集原理

    一.简介 Video for Linuxtwo(Video4Linux2)简称V4L2,是V4L的改进版.V4L2是linux操作系统下用于采集图片.视频和音频数据的API接口,配合适当的视频采集设备 ...

  6. eclipse export runnable jar(导出可执行jar包) runnable jar可以执行的

    如果要导出可运行的JAR文件,需要选择Runnable Jar File. 1. 选择要到处JAR文件的工程,右键选择“Export”: 2. 选择“Java-->Runnable JAR fi ...

  7. IComparable和IComparer接口

    C#中,自定义类型,支持比较和排序,需要实现IComparable接口.IComparable接口存在一个名为CompareTo()的方法,接收类型为object的参数表示被比较对象,返回整型值:1表 ...

  8. 题解 P4305 【[JLOI2011]不重复数字】

    来一波用vector的最短代码题解 P4305 [JLOI2011]不重复数字 关于hash表的部分大家可以看一看其他的题解,我就不说了 不定长数组vector的几个基本用法: 定义: vector& ...

  9. Taro-UI 2.0样式在H5上生效,微信小程序不生效?

    答案: https://taro-ui.aotu.io/#/docs/questions taro-ui 自定义样式覆盖小程序组件样式使用到了 globalClass 这个微信小程序特性,由于微信小程 ...

  10. 一个小问题 关于 com.mysql.jdbc.PacketTooBigException: Packet for query is too large

    这个错本身就是应为传输的数据大于mysql的max_allowed_packet参数默认值造成的: 之前遇到这个问题,一直是改max_allowed_packet的值 ,做项目遇到这个错误改了好几次, ...