cb28a_c++_STL_算法_查找算法_(1)find_find_if
cb28a_c++_STL_算法_查找算法_(1)find_find_if
find() //线性查找,比较慢。
pos1 = find(ilist.begin(), ilist.end(), 5);
find_if()
search_n()
search()
find_end()
find_first_of()
adjacent_find()
注意:
1.如果是已序区间,可以使用已序区间的查找算法(效率高)
binary_search()
includes()
lower_bound()
upper_bound()
2.关联是容器有等效的成员函数find(),set,map
3.string有等效的成员函数find(),不能使用 算法的 find(),find_if().算法的find适合所有容器使用
- /*cb28a_c++_STL_算法_查找算法_(1)find_find_if
- find() //线性查找,比较慢。
- pos1 = find(ilist.begin(), ilist.end(), 5);
- find_if()
- search_n()
- search()
- find_end()
- find_first_of()
- adjacent_find()
- 注意:
- 1.如果是已序区间,可以使用已序区间的查找算法(效率高)
- binary_search()
- includes()
- lower_bound()
- upper_bound()
- 2.关联是容器有等效的成员函数find(),set,map
- 3.string有等效的成员函数find(),不能使用 算法的 find(),find_if().算法的find适合所有容器使用
- */
- #include <iostream>
- #include <algorithm>
- #include <list>
- using namespace std;
- int main()
- {
- list<int> ilist;
- for (int i = ; i <= ; ++i)
- ilist.insert(ilist.end(), i);
- 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;
- list<int>::iterator pos1;
- pos1 = find(ilist.begin(), ilist.end(), );
- cout << "找到后返回迭代器" << endl;
- list<int>::iterator pos2;
- if (pos1 != ilist.end())
- {
- pos2 = find(++pos1, ilist.end(), );
- }
- if (pos1 != ilist.end() && pos2 != ilist.end())
- {
- cout << "显示两个5之间的数据" << endl;
- for (list<int>::iterator iter = pos1; iter != pos2; ++iter)
- cout << *iter << ' ';
- cout << endl;
- }
- }
- /*cb28b_c++_
- */
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <functional>
- using namespace std;
- int main()
- {
- vector<int> ivec;
- vector<int>::iterator pos;
- for (int i = ; i >= ; --i)
- ivec.push_back(i);
- for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); ++iter)
- cout << "vector数据是:" << *iter << ' ';
- cout << endl;
- pos = find_if(ivec.begin(), ivec.end(), bind2nd(greater<int>(), ));
- //https://www.cnblogs.com/txwtech/p/12330413.html
- cout <<"大于3的数: "<< *pos << endl;
- pos = find_if(ivec.begin(), ivec.end(), not1(bind2nd(modulus<int>(), )));
- //modulus取模运算:找一个被3整除的数,找到后,bind2nd返回的取模的结果是0
- //not1取反,就可以返回1
- //https://www.cnblogs.com/txwtech/p/12330413.html
- cout << "找一个被3整除的数: " <<*pos<< endl;
- return ;
- }
- /*cb28c_c++
- txwtech@163.com
- */
- #include <iostream>
- #include <set>
- using namespace std;
- int main()
- {
- set<int> iset;
- iset.insert(); //插入数据,自动排序。已序区间
- iset.insert();
- iset.insert(-);
- iset.insert();
- for (set<int>::iterator iter = iset.begin(); iter != iset.end(); ++iter)
- cout << *iter << ' ';
- cout << endl;
- set<int>::iterator pos;
- pos = iset.find();//类似2分查找,速度快
- if (pos != iset.end())
- cout << "找到了" << *pos << endl;
- else
- cout << "没找到" << endl;
- return ;
- }
- /*cb28d
- */
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string s("AnnaBelle");
- string::size_type pos = s.find("nna");
- if (pos != string::npos)
- cout << "找到了,下标是:" << pos << endl;
- else
- cout << "没找到" << endl;
- pos = s.find("bell");
- if (pos != string::npos)
- cout << "找到了,下标是:" << pos << endl;
- else
- cout << "没找到" << endl;
- return ;
- }
cb28a_c++_STL_算法_查找算法_(1)find_find_if的更多相关文章
- cb34a_c++_STL_算法_查找算法_(7)_lower_bound
cb34a_c++_STL_算法_查找算法_(7)_lower_bound//针对已序区间的查找算法,如set,multiset关联容器-自动排序lower_bound()--第一个可能的位置uppe ...
- cb33a_c++_STL_算法_查找算法_(6)binary_search_includes
cb33a_c++_STL_算法_查找算法_(6)binary_search_includes//针对已序区间的查找算法,如set,multiset关联容器-自动排序binary_search(b,e ...
- 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 ...
- 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 //二分查 ...
随机推荐
- Event Loop、 宏任务和微任务
本文将介绍我自己对JS Event Loop 和 宏任务.微任务的理解. 二话不说先上图: 接下来将会针对此图讲解什么是Event Loop 什么事宏任务和微任务(其实聪明的你们通过图大体也能了解的是 ...
- C#中的List基础用法汇总
List类是ArrayList类的泛型等效类,该类使用大小可按需动态增加的数组实现IList泛型接口. 泛型的好处:它为使用c#语言编写面向对象程序增加了极大的效力和灵活性.不会强行对值类型进行装箱和 ...
- 从Point类继承的Circle类 代码参考
#include <iostream> #include <cstring> using namespace std; class Point { private: int x ...
- Java中方法的重载与重写
1.方法的名字和参数列表称为方法的签名:每个方法具有唯一与其对应的签名: 2.方法的重载:在某个类中,存在具有多个相同名字不同参数列表的方法,称之为重载: 被重载的方法必须改变参数列表(参数个数或类型 ...
- 多用户vps管理面板怎么安装,有没有好用的vps管理工具
一.VPS安装VPSMate控制面板步骤 1.使用SSH连接到VPS.使用命令获取VPSMate安装包: wget http://www.vpsmate.org/tools/install.py ...
- Rocket - debug - TLDebugModuleInner - DMI Register Control and Status
https://mp.weixin.qq.com/s/tI41wu0xaIQ5PRq6F82tNw 简单介绍TLDebugModuleInner中生成DMI控制和状态寄存器使用到的状态. 1. abs ...
- 非阻塞赋值(Non-blocking Assignment)是个伪需求(2)
https://mp.weixin.qq.com/s/5NWvdK3T2X4dtyRqtNrBbg 13hope: 个人理解,Verilog本身只是“建模”语言.具体到阻塞/非阻塞,只规定了两种赋 ...
- python初学者笔记(2):阿拉伯数字转换成中文大写
题:输入一个数字,转换成中文大写的写法 可运行的程序(Python 2.7.9): # -*- coding: utf-8 -*- #在python2的py文件里面写中文,必须要添加一行声明文件编码的 ...
- [译]深入理解JVM Understanding JVM Internals
转载: 英文原版地址:http://www.cubrid.org/blog/dev-platform/understanding-jvm-internals/ 翻不了墙的可以看这个英文版:https: ...
- footer部分,当页面主题内容不满一屏时,始终位于页面底部
比如上面这种情况,footer部分本来应该位于最底部,但是main内容太少导致连在一起,影响美观 解决方案: 给footer加上margin-top:负值 值的大小为footer的高度 写了个小dem ...