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 //二分查 ...
随机推荐
- Vue全局组件创建三种方法
<my-com1></my-com1> <my-com2></my-com2> <template id="tmp1"> ...
- 基于Pytest豆瓣自动化测试【1】
-- Pytest基础使用教程[1] 引言 Pytest 是一个非常实用的自动化测试框架,目前来说资料也是非常多了.最近某友人在学习 Python的一些测试技术,帮其网上搜了下教程:发现大多数文章多是 ...
- 重学 Java 设计模式:实战原型模式
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 老板你加钱我的代码能飞 程序员这份工作里有两种人:一类是热爱喜欢的.一类是仅当成工作 ...
- [Python番外]001.用Sublime开发Python
用Sublime开发Python 准备 安装Package Control插件 安装Python插件 Python环境配置 修改快捷键 准备 安装Python 详见 Python准备 下载Sublim ...
- Java集合(八)哈希表及哈希函数的实现方式
Java集合(八)哈希表及哈希函数的实现方式 一.哈希表 非哈希表的特点:关键字在表中的位置和它之间不存在一个确定的关系,查找的过程为给定值一次和各个关键字进行比较,查找的效率取决于和给定值进行比较的 ...
- burpsuite 关于部分https抓包失败原因
没导入证书 burpsuite生成证书 der格式,名字随便取,一路next firefox浏览器导入 导入,勾选信任证书ok,重启浏览器 还有你要勾选这里,确保所有流量都走你的代理 ps:遇到浏 ...
- 基于Basys2开发板的简易电子琴和音乐播放器设计
背景:华中科技大学 电测综合实验 主要功能:Basys2开发板外接一个扬声器(或无源蜂鸣器也可)实现电子琴和音乐播放器的功能.其中由于开发板上只有4个按键,所以电子琴功能只做了4个音调,分别对应于4个 ...
- (易忘篇)java基本语法难点2
1.不同类型的一维数组元素的默认初始化值 整型元素 : 0 boolean型元素 : false 浮点型元素 : 0.0 char型元素 : 0或'\u0000',而非'0' 引用类型元素 : nul ...
- SQL Server使用Offset/Fetch Next实现分页
T-SQL实现分页 ,查找指定范围内的数据 首先,正常的查询是这样的 使用分页后 select * from Products order by ProductID offset X rows fet ...
- java实现 洛谷 P1056 排座椅
import java.util.Arrays; import java.util.Map.Entry; import java.util.Scanner; import java.util.Tree ...