cb33a_c++_STL_算法_查找算法_(6)binary_search_includes
cb33a_c++_STL_算法_查找算法_(6)binary_search_includes
//针对已序区间的查找算法,如set,multiset关联容器-自动排序
binary_search(b,e,v),begin,end,value--返回bool,不会告诉具体找到的位置。只能找一个
if (binary_search(iset.begin(), iset.end(), 5))//返回bool
binary_search(b,e,v,p) begin,end, value,parameter(谓词)
includes(b,e,sb,se)--begin,end,second begin,second end.可以找多个,不连续的。查找对象必须是排序的,顺序存放的数据。
if(includes(iset.begin(),iset.end(),search.begin(),search.end()))
include (b,e,sb,se,p)--p,parameter,谓词
lower_bound()--找到后,可以返回位置
/*cb33a_c++_STL_算法_查找算法_(6)binary_search_includes
//针对已序区间的查找算法,如set,multiset关联容器-自动排序
binary_search(b,e,v),begin,end,value--返回bool,不会告诉具体找到的位置。只能找一个
if (binary_search(iset.begin(), iset.end(), 5))//返回bool
binary_search(b,e,v,p) begin,end, value,parameter(谓词) includes(b,e,sb,se)--begin,end,second begin,second end.可以找多个,不连续的。查找对象必须是排序的,顺序存放的数据。
if(includes(iset.begin(),iset.end(),search.begin(),search.end()))
include (b,e,sb,se,p)--p,parameter,谓词 lower_bound()--找到后,可以返回位置
*/ #include <iostream>
#include <algorithm>
#include <list>
#include <set>
#include <vector> using namespace std; int main()
{
list<int> ilist;
for (int i = ; i <= ; ++i)
ilist.insert(ilist.end(), i);//从后面插入
ilist.push_back();
set<int> iset;
for (int ii = ; ii <= ; ++ii)
iset.insert(iset.end(), ii);
iset.insert(iset.end(),);//即使在最后插入的0,它也会自动排序,0会移动到最前面的 for (list<int>::iterator iter = ilist.begin(); iter != ilist.end(); ++iter)
cout << *iter << ' ';
cout << endl;
cout << "set容器结果查看" << endl;
for (set<int>::iterator iter = iset.begin(); iter != iset.end(); ++iter)
cout << *iter << ' ';
cout << endl; if (binary_search(iset.begin(), iset.end(), ))//返回bool
cout << "找到了" << endl;
else
cout << "没找到" << endl; vector<int> search; //
search.push_back();
search.push_back();
search.push_back();
if(includes(iset.begin(),iset.end(),search.begin(),search.end()))
cout<<"iset里面找 search vector的,3,4,7。同时都找到了"<<endl;
//只要包含 3,4,7,就算找到了
//注意,vector如果没有顺序排放,就会出错的。3,7,4就不可以。
//已序区间,就是已经排序的区域。默认排序的,或者自动排序的容器
else
cout << "没找到" << endl; return ;
}
cb33a_c++_STL_算法_查找算法_(6)binary_search_includes的更多相关文章
- cb34a_c++_STL_算法_查找算法_(7)_lower_bound
cb34a_c++_STL_算法_查找算法_(7)_lower_bound//针对已序区间的查找算法,如set,multiset关联容器-自动排序lower_bound()--第一个可能的位置uppe ...
- cb32a_c++_STL_算法_查找算法_(5)adjacent_find
cb32a_c++_STL_算法_查找算法_(5)adjacent_findadjacent_find(b,e),b,begin(),e,end()adjacent_find(b,e,p),p-par ...
- cb31a_c++_STL_算法_查找算法_(4)find_first_of
cb31a_c++_STL_算法_查找算法_(4)find_first_offind_first_of(b,e,sb,se),sb,second begin, se,second end();find ...
- cb30a_c++_STL_算法_查找算法_(3)search_find_end
cb30a_c++_STL_算法_查找算法_(3)search_find_endsearch()pos = search(ideq.begin(), ideq.end(), ilist.begin() ...
- cb29a_c++_STL_算法_查找算法_(2)search_n
cb29a_c++_STL_算法_查找算法_(2)search_n//比如:连续查找连续的n个8search_n(b,e,c,v),迭代器b,begin(),e,end().连续的c个vpos=sea ...
- cb28a_c++_STL_算法_查找算法_(1)find_find_if
cb28a_c++_STL_算法_查找算法_(1)find_find_iffind() //线性查找,比较慢.pos1 = find(ilist.begin(), ilist.end(), 5);fi ...
- STL_算法_查找算法(lower_bound、upper_bound、equal_range)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n))) 已序区间查找算法 lower_bound() //找第一个符合的 ...
- STL_算法_查找算法(find、find_if)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) find(); find_if ...
- STL_算法_查找算法(binary_search、includes)
C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n))) 已序区间查找算法 binary_search //二分查 ...
随机推荐
- idea的生成类注释和方法注释
sttings中选择 类注释 /** * @program: ${PROJECT_NAME} * * @description: ${description} * * @author: xiaozha ...
- Spring_bean作用域
本篇介绍Spring Bean实例的作用范围,Spring Bean实例的作用范围由配置项scope限定.通过本篇的学习,可以达成如下目标. ● 应用scope配置项配置Bean的作用域 ● 应用单例 ...
- sku算法介绍及实现
前言 做过电商项目前端售卖的应该都遇见过不同规格产品库存的计算问题,业界名词叫做sku(stock Keeping Unit),库存量单元对应我们售卖的具体规格,比如一部手机具体型号规格,其中ipho ...
- git的相关基础操作
一.git安装 从https://git-scm.com/下载相应版本安装即可,一路默认安装到底即可,安装目录可以自行选择 二.git配置 安装完git后在任意文件夹内单击鼠标右键,会出现Git GU ...
- 循序渐进VUE+Element 前端应用开发(6)--- 常规Element 界面组件的使用
在我们开发BS页面的时候,往往需要了解常规界面组件的使用,小到最普通的单文本输入框.多文本框.下拉列表,以及按钮.图片展示.弹出对话框.表单处理.条码二维码等等,本篇随笔基于普通表格业务的展示录入的场 ...
- 【Java8新特性】重复注解与类型注解,你真的学会了吗?
写在前面 在Java8之前,在某个类或者方法,字段或者参数上标注注解时,同一个注解只能标注一次.但是在Java8中,新增了重复注解和类型注解,也就是说,从Java8开始,支持在某个类或者方法,字段或者 ...
- 学Linux驱动: 应该先了解驱动模型
[导读] Linux设备林林总总,嵌入式开发一个绕不开的话题就是设备驱动开发,在做具体设备驱动开发之前,有必要对Linux设驱动模型有一个相对清晰的认识,将会帮助驱动开发,明白具体驱动接口操作符相应都 ...
- JAVASE(八) 数组: 一维数组、二维数组、动态数组、静态数组
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 1.一维数组 1.1 数组的声明和初始化声明方式: String str[]; //不建议使用 Stri ...
- Java实现蓝桥杯模拟组织晚会
问题描述 小明要组织一台晚会,总共准备了 n 个节目.然后晚会的时间有限,他只能最终选择其中的 m 个节目. 这 n 个节目是按照小明设想的顺序给定的,顺序不能改变. 小明发现,观众对于晚上的喜欢程度 ...
- Java实现 LeetCode 68 文本左右对齐
68. 文本左右对齐 给定一个单词数组和一个长度 maxWidth,重新排版单词,使其成为每行恰好有 maxWidth 个字符,且左右两端对齐的文本. 你应该使用"贪心算法"来放置 ...