博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
二分检索函数lower_bound()和upper_bound()
阅读量:7282 次
发布时间:2019-06-30

本文共 765 字,大约阅读时间需要 2 分钟。

二分检索函数lower_bound()和upper_bound()

一、说明

头文件:<algorithm>

二分检索函数lower_bound()和upper_bound()

lower_bound():找到大于等于某值的第一次出现
upper_bound():找到大于某值的第一次出现
必须从小到大排序后才能用
内部查找方式为二分查找,二分查找必定需要排序

返回值为地址

 

二、代码及结果

1 /* 2 二分检索函数lower_bound()和upper_bound()  3 lower_bound():找到大于等于某值的第一次出现 4 upper_bound():找到大于某值的第一次出现 5 必须从小到大排序后才能用  6 内部查找方式为二分查找,二分查找必定需要排序  7 返回值为地址  8 */ 9 #include 
10 #include
11 #include
12 using namespace std;13 14 15 int main(){16 17 int a[]={
9,2,4,5,10,7,30};18 sort(a,a+7);//省略掉排序规则的形式,默认从小到大 19 //sort(a,a+7,less
());//用系统的排序规则,从小到大 20 //sort(a,a+7,greater
());//用系统的排序规则,从大到小 21 for(int i=0;i<7;i++){22 cout<
<<" "<<&a[i]<

 

转载地址:http://gwkjm.baihongyu.com/

你可能感兴趣的文章
erlang判定闰年,并用eunit测试
查看>>
DatetimeUtil工具类--用于Date和字符串互转的工具类
查看>>
escape()、encodeURI()、encodeURIComponent()区别详解
查看>>
GitLab 7.13.x安装和配置<二>--Linux篇
查看>>
mybatis调用oracle存储过程
查看>>
shell练习五
查看>>
踩坑Apache HttpEntity
查看>>
Core Data的使用(二)
查看>>
MYSQL外键(Foreign Key)的使用
查看>>
导入开源库到基于Android Studio构建的项目中
查看>>
Maven 在eclispe中集成本地插件报错解决方案
查看>>
Ubuntu中必装的十个应用程序
查看>>
Object-c 单例模式中的 allocWithZone作用
查看>>
分享一个H5原生form表单的checkbox特效
查看>>
nodejs+npm+webpack+vue+ElementUI+vue-route
查看>>
JAVA编程插入Excel文件到Word数据区域
查看>>
Highcharts 3.0.8功能特性使用评测
查看>>
大型分布式网站架构实战项目分析
查看>>
python 图片处理 窗体
查看>>
游戏开发--开源软件6--LimeJS(javascript)||Gamvas||gamejs
查看>>