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适合所有容器使用

  1. /*cb28a_c++_STL_算法_查找算法_(1)find_find_if
  2. find() //线性查找,比较慢。
  3. pos1 = find(ilist.begin(), ilist.end(), 5);
  4. find_if()
  5. search_n()
  6. search()
  7. find_end()
  8. find_first_of()
  9. adjacent_find()
  10. 注意:
  11. 1.如果是已序区间,可以使用已序区间的查找算法(效率高)
  12. binary_search()
  13. includes()
  14. lower_bound()
  15. upper_bound()
  16. 2.关联是容器有等效的成员函数find(),set,map
  17. 3.string有等效的成员函数find(),不能使用 算法的 find(),find_if().算法的find适合所有容器使用
  18. */
  19.  
  20. #include <iostream>
  21. #include <algorithm>
  22. #include <list>
  23.  
  24. using namespace std;
  25. int main()
  26. {
  27. list<int> ilist;
  28. for (int i = ; i <= ; ++i)
  29. ilist.insert(ilist.end(), i);
  30. for (int i = ; i <= ; ++i)
  31. ilist.insert(ilist.end(), i);
  32. for (list<int>::iterator iter = ilist.begin(); iter != ilist.end(); ++iter)
  33. cout << *iter << ' ';
  34. cout << endl;
  35.  
  36. list<int>::iterator pos1;
  37. pos1 = find(ilist.begin(), ilist.end(), );
  38. cout << "找到后返回迭代器" << endl;
  39. list<int>::iterator pos2;
  40. if (pos1 != ilist.end())
  41. {
  42. pos2 = find(++pos1, ilist.end(), );
  43.  
  44. }
  45. if (pos1 != ilist.end() && pos2 != ilist.end())
  46. {
  47. cout << "显示两个5之间的数据" << endl;
  48. for (list<int>::iterator iter = pos1; iter != pos2; ++iter)
  49. cout << *iter << ' ';
  50. cout << endl;
  51. }
  52.  
  53. }
  1. /*cb28b_c++_
  2.  
  3. */
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <functional>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. vector<int> ivec;
  14. vector<int>::iterator pos;
  15.  
  16. for (int i = ; i >= ; --i)
  17. ivec.push_back(i);
  18. for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); ++iter)
  19. cout << "vector数据是:" << *iter << ' ';
  20. cout << endl;
  21.  
  22. pos = find_if(ivec.begin(), ivec.end(), bind2nd(greater<int>(), ));
  23. //https://www.cnblogs.com/txwtech/p/12330413.html
  24. cout <<"大于3的数: "<< *pos << endl;
  25.  
  26. pos = find_if(ivec.begin(), ivec.end(), not1(bind2nd(modulus<int>(), )));
  27. //modulus取模运算:找一个被3整除的数,找到后,bind2nd返回的取模的结果是0
  28. //not1取反,就可以返回1
  29. //https://www.cnblogs.com/txwtech/p/12330413.html
  30. cout << "找一个被3整除的数: " <<*pos<< endl;
  31. return ;
  32. }
  1. /*cb28c_c++
  2.  
  3. txwtech@163.com
  4. */
  5.  
  6. #include <iostream>
  7. #include <set>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. set<int> iset;
  14. iset.insert(); //插入数据,自动排序。已序区间
  15. iset.insert();
  16. iset.insert(-);
  17. iset.insert();
  18.  
  19. for (set<int>::iterator iter = iset.begin(); iter != iset.end(); ++iter)
  20. cout << *iter << ' ';
  21. cout << endl;
  22. set<int>::iterator pos;
  23. pos = iset.find();//类似2分查找,速度快
  24. if (pos != iset.end())
  25. cout << "找到了" << *pos << endl;
  26. else
  27. cout << "没找到" << endl;
  28.  
  29. return ;
  30. }
  1. /*cb28d
  2. */
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. string s("AnnaBelle");
  11.  
  12. string::size_type pos = s.find("nna");
  13. if (pos != string::npos)
  14. cout << "找到了,下标是:" << pos << endl;
  15. else
  16. cout << "没找到" << endl;
  17.  
  18. pos = s.find("bell");
  19. if (pos != string::npos)
  20. cout << "找到了,下标是:" << pos << endl;
  21. else
  22. cout << "没找到" << endl;
  23.  
  24. return ;
  25. }

cb28a_c++_STL_算法_查找算法_(1)find_find_if的更多相关文章

  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. cb30a_c++_STL_算法_查找算法_(3)search_find_end

    cb30a_c++_STL_算法_查找算法_(3)search_find_endsearch()pos = search(ideq.begin(), ideq.end(), ilist.begin() ...

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

  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. Event Loop、 宏任务和微任务

    本文将介绍我自己对JS Event Loop 和 宏任务.微任务的理解. 二话不说先上图: 接下来将会针对此图讲解什么是Event Loop 什么事宏任务和微任务(其实聪明的你们通过图大体也能了解的是 ...

  2. C#中的List基础用法汇总

    List类是ArrayList类的泛型等效类,该类使用大小可按需动态增加的数组实现IList泛型接口. 泛型的好处:它为使用c#语言编写面向对象程序增加了极大的效力和灵活性.不会强行对值类型进行装箱和 ...

  3. 从Point类继承的Circle类 代码参考

    #include <iostream> #include <cstring> using namespace std; class Point { private: int x ...

  4. Java中方法的重载与重写

    1.方法的名字和参数列表称为方法的签名:每个方法具有唯一与其对应的签名: 2.方法的重载:在某个类中,存在具有多个相同名字不同参数列表的方法,称之为重载: 被重载的方法必须改变参数列表(参数个数或类型 ...

  5. 多用户vps管理面板怎么安装,有没有好用的vps管理工具

    一.VPS安装VPSMate控制面板步骤 1.使用SSH连接到VPS.使用命令获取VPSMate安装包: wget   http://www.vpsmate.org/tools/install.py ...

  6. Rocket - debug - TLDebugModuleInner - DMI Register Control and Status

    https://mp.weixin.qq.com/s/tI41wu0xaIQ5PRq6F82tNw 简单介绍TLDebugModuleInner中生成DMI控制和状态寄存器使用到的状态. 1. abs ...

  7. 非阻塞赋值(Non-blocking Assignment)是个伪需求(2)

    https://mp.weixin.qq.com/s/5NWvdK3T2X4dtyRqtNrBbg   13hope: 个人理解,Verilog本身只是“建模”语言.具体到阻塞/非阻塞,只规定了两种赋 ...

  8. python初学者笔记(2):阿拉伯数字转换成中文大写

    题:输入一个数字,转换成中文大写的写法 可运行的程序(Python 2.7.9): # -*- coding: utf-8 -*- #在python2的py文件里面写中文,必须要添加一行声明文件编码的 ...

  9. [译]深入理解JVM Understanding JVM Internals

    转载: 英文原版地址:http://www.cubrid.org/blog/dev-platform/understanding-jvm-internals/ 翻不了墙的可以看这个英文版:https: ...

  10. footer部分,当页面主题内容不满一屏时,始终位于页面底部

    比如上面这种情况,footer部分本来应该位于最底部,但是main内容太少导致连在一起,影响美观 解决方案: 给footer加上margin-top:负值 值的大小为footer的高度 写了个小dem ...