cb30a_c++_STL_算法_查找算法_(3)search_find_end
search()
pos = search(ideq.begin(), ideq.end(), ilist.begin(), ilist.end());
find_end(),从后面开始找

注意:
这两个算法是一对
第二个算法应该叫search_end(),但是被命名为find_end()

pos2 = search(ivec.begin(), ivec.end(),checkEvenArgs,checkEvenArgs+3, checkEven);
//ivec.begin(), ivec.end()传给第一个参数,elem.
//,checkEvenArgs,checkEvenArgs+3,传给checkEven的第二个参数,even
//bool checkEven(int elem, bool even)//二元谓词,两个return

 /*cb30a_c++_STL_算法_查找算法_(3)search_find_end
search()
pos = search(ideq.begin(), ideq.end(), ilist.begin(), ilist.end());
find_end(),从后面开始找 注意:
这两个算法是一对
第二个算法应该叫search_end(),但是被命名为find_end() pos2 = search(ivec.begin(), ivec.end(),checkEvenArgs,checkEvenArgs+3, checkEven);
//ivec.begin(), ivec.end()传给第一个参数,elem.
//,checkEvenArgs,checkEvenArgs+3,传给checkEven的第二个参数,even
//bool checkEven(int elem, bool even)//二元谓词,两个return
*/
#include <iostream>
#include <algorithm>
#include <deque>
#include <list>
#include <vector> using namespace std; //1,2,2,4,5
//true, false, true
//false表示奇数
//true 偶数 bool checkEven(int elem, bool even)//二元谓词,两个return
{
if (even)
return elem % == ;//
else
return elem % == ;//
}
//把 true, false, true,三个传进去,连续3个都返回true,说明查找到了。 int main()
{
deque<int> ideq;
list<int> ilist;
for (int i = ; i <= ; ++i)
ideq.insert(ideq.end(), i);//插入到最后
for (int i = ; i <= ; ++i)
ideq.insert(ideq.end(), i);//插入到最后
for (deque<int>::iterator iter = ideq.begin(); iter != ideq.end(); ++iter)
cout << *iter << ' ';
cout << endl;
for (int i = ; i <= ; ++i)
ilist.insert(ilist.end(), i);
for (list<int>::iterator iter = ilist.begin(); iter != ilist.end(); ++iter)
cout << *iter << ' ';
cout << endl; deque<int>::iterator pos;
pos = search(ideq.begin(), ideq.end(), ilist.begin(), ilist.end());
cout << "在ideq容器里面找ilist" << endl;
if (pos != ideq.end())
cout << "找到了位置:" << distance(ideq.begin(), pos)+ << endl;
else
cout << "没找到" << endl;
++pos;
pos = search(pos, ideq.end(), ilist.begin(), ilist.end());
cout << "在ideq容器里面找ilist" << endl;
if (pos != ideq.end())
cout << "找到了位置:" << distance(ideq.begin(), pos)+ << endl;
else
cout << "没找到" << endl; cout << "使用find_end,从后面开始查找。进行查找:" << endl;
pos = find_end(ideq.begin(), ideq.end(), ilist.begin(), ilist.end()); if (pos != ideq.end())
cout << "找到了位置:" << distance(ideq.begin(), pos) + << endl;
else
cout << "没找到" << endl; cout << "使用谓词查找" << endl; vector<int> ivec;
bool checkEvenArgs[] = {true,false,true};
for (int i = ; i <= ; ++i)
ivec.push_back(i);
for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); ++iter)
cout << *iter << ' ';
cout << endl;
vector<int>::iterator pos2;
pos2 = search(ivec.begin(), ivec.end(),checkEvenArgs,checkEvenArgs+, checkEven);
//ivec.begin(), ivec.end()传给第一个参数,elem.
//,checkEvenArgs,checkEvenArgs+3,传给checkEven的第二个参数,even
//bool checkEven(int elem, bool even)//二元谓词,两个return //1,2,3,4,5,6,7
//true,false,true. 对应2,3,4。所以在第二就找到了。显示2
if (pos2 != ivec.end())
cout << "找到了,位置是:" << distance(ivec.begin(), pos2)+ << endl;
else
cout << "没找到" << endl;
return ;
}

cb30a_c++_STL_算法_查找算法_(3)search_find_end的更多相关文章

  1. cb34a_c++_STL_算法_查找算法_(7)_lower_bound

    cb34a_c++_STL_算法_查找算法_(7)_lower_bound//针对已序区间的查找算法,如set,multiset关联容器-自动排序lower_bound()--第一个可能的位置uppe ...

  2. cb33a_c++_STL_算法_查找算法_(6)binary_search_includes

    cb33a_c++_STL_算法_查找算法_(6)binary_search_includes//针对已序区间的查找算法,如set,multiset关联容器-自动排序binary_search(b,e ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. cb28a_c++_STL_算法_查找算法_(1)find_find_if

    cb28a_c++_STL_算法_查找算法_(1)find_find_iffind() //线性查找,比较慢.pos1 = find(ilist.begin(), ilist.end(), 5);fi ...

  7. STL_算法_查找算法(lower_bound、upper_bound、equal_range)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n)))    已序区间查找算法 lower_bound()        //找第一个符合的 ...

  8. STL_算法_查找算法(find、find_if)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) find(); find_if ...

  9. STL_算法_查找算法(binary_search、includes)

    C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n)))     已序区间查找算法 binary_search             //二分查 ...

随机推荐

  1. 补充_001_问题_001_Vivian

    在此先向前辈们和同学们道个歉,一是没有认真地专研前辈们的精文,二是对一些读者造成了一定程度上的困扰,为此鄙人深感抱歉,现在对"问题_001_Vivian"中不严谨的地方进行修改: ...

  2. 0507 构造代码块和static案例,接口interface

    0507构造代码块和static案例,接口interface [重点] 1.局部变量,成员变量,静态变量的特点 2.接口 接口语法:interface A {} 接口内的成员变量[缺省属性]publi ...

  3. DFS与DP算法

    名词解释: DFS(Dynamic Plan):动态规划 DFS(Depth First Search):深度优先搜索 DFS与DP的关系 很多情况下,dfs和dp两种解题方法的思路都是很相似的,这两 ...

  4. 【汇总】 为园友写的皮肤制作工具 awescnb

    Awescnb, awesome cnblog. 简介 可能许多初来乍到的新手会被博客园经典的风格劝退,或者您是一个老园友,需要为您的博客定制一些功能(例如宣传公众号,文章目录.或者插入几个捐助二维码 ...

  5. 关于hexo-blog-encrypt插件输入密码后无响应的问题

    解决方案:更改网站为https协议 具体请查看: https://github.com/MikeCoder/hexo-blog-encrypt/issues/114

  6. 实用教程丨使用K3s和MySQL运行Rancher 2.4

    本文转自Rancher Labs 简 介 本文将介绍在高可用K3s Kubernetes集群上安装Rancher 2.4的过程并针对MySQL利用Microsoft Azure数据库的优势,该数据库消 ...

  7. Telegraf和Grafana监控多平台上的SQL Server

    问题 SQL Server在很多企业中部署在多个平台上(Windows,Linux和Container),需要一种能支持多平台的解决方案用于收集和展示相关的监控指标. 我选择企业中比较流行的监控展示工 ...

  8. js匿名函数和date对象,math对象

    匿名函数: <script type="text/javascript"> function (参数列表){ 要执行的语句块; } </script> 对象 ...

  9. (Java实现) 洛谷 P1319 压缩技术

    题目描述 设某汉字由N X N的0和1的点阵图案组成,如下图.我们依照以下规则生成压缩码.连续一组数值:从汉字点阵图案的第一行第一个符号开始计算,按书写顺序从左到右,由上至下.第一个数表示连续有几个0 ...

  10. 一招解决GitHub致命的下载速度(GitHub下载速度慢怎么办)

    通过码云来导入github,通过码云下载 第一步: 找一个你需要下载的GitHub项目 第二步: 复制链接 第三步: 打开码云,然后选择从GitHub导入 第四步: 复制刚才的连接,起个名字,点击导入 ...