#include <iostream>
#include <algorithm>
#include <list>
#include <functional>
#include <vector>

using namespace std;

//已序区间查找
int main()
{
  list<int> list1;
  for (int k = 0; k < 10; k++)
  {
    list1.insert(list1.end(), k);
  }

  list<int>::iterator list_iter1;
  for (list_iter1 = list1.begin(); list_iter1 != list1.end(); ++list_iter1)
  {
    cout << *list_iter1 << " ";
  }
  cout << endl;

  list<int>::iterator list_iter2;
  bool isFound = binary_search(list1.begin(), list1.end(), 5);
  if (isFound)
  {
    cout << "found element..." << endl;
  }
  else
  {
    cout << "not found..." << endl;
  }

  cout << "---------------------------------" << endl;

  vector<int> vec1;
  for (int k=4;k<8;k++)
  {
    vec1.push_back(k);
  }
  
  //includes 查找不用连续,如果查找连续,用search
  bool isFound2 = includes(list1.begin(), list1.end(), vec1.begin(), vec1.end());
  if (isFound2)
  {
    cout << "found element..." << endl;
  }
  else
  {
    cout << "not found..." << endl;
  }

  cout << "---------------------------------------------------" << endl;
  vec1.push_back(56);
  bool isFound3 = includes(list1.begin(), list1.end(), vec1.begin(), vec1.end());
  if (isFound3)
  {
    cout << "found element..." << endl;
  }
  else
  {
    cout << "not found..." << endl;
  }

  system("pause");
  return 0;
}

===================================================

0 1 2 3 4 5 6 7 8 9
found element...
---------------------------------
found element...
---------------------------------------------------
not found...
请按任意键继续. . .

C++ STL 已序区间查找算法的更多相关文章

  1. STL学习笔记(已序区间算法)

    针对已序区间执行的算法,执行前提是源区间必须在某个排序准则下已序. 搜寻元素(Searching) 1.检查某个元素是否存在 bool binary_search(ForwardIterator be ...

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

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

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

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

  4. C++ STL之查找算法

    C++STL有好几种查找算法,但是他们的用法上有很多共同的地方: 1.除了binary_search的返回值是bool之外(查找的了返回true,否则返回false),其他所有的查找算法返回值都是一个 ...

  5. 从零开始学C++之STL(四):算法简介、7种算法分类

    一.算法 算法是以函数模板的形式实现的.常用的算法涉及到比较.交换.查找.搜索.复制.修改.移除.反转.排序.合并等等. 算法并非容器类型的成员函数,而是一些全局函数,要与迭代器一起搭配使用. 算法的 ...

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

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

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

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

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

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

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

随机推荐

  1. 快速认识Python

    1.数字和表达式 什么是表达式,1+2*3 就是一个表达式,这里的加号和乘号叫做运算符,1.2.3叫做操作数.1+2*3 经过计算后得到的结果是7,就1+2*3 = 7.我们可以将计算结果保存在一个变 ...

  2. OpenCV读取图像问题:OpenCV(3.4.3) D:\Build\OpenCV\opencv-size.width0 && size.height0 in function 'cvimshow'

    版权声明:本文为博主原创文章,转载 请注明出处:https://blog.csdn.net/sc2079/article/details/83280067 - 问题与解决 最近正在学OpenCV,发现 ...

  3. (1)openstack-Rabbitmq 集群部署

    一.前期准备   (1)条件:准备3台linux系统,确保配置好源,及epel源  yun1,yun2,yun3   (2)三台机器能够静态解析彼此   (3)设置可以无密钥登陆  ssh-keyge ...

  4. Juit

    Junit这种老技术,现在又拿出来说,不为别的,某种程度上来说,更是为了要说明它在项目中的重要性. 凭本人的感觉和经验来说,在项目中完全按标准都写Junit用例覆盖大部分业务代码的,应该不会超过一半. ...

  5. java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present

    @Controller@ComponentScan@Configuration@EnableScheduling@EnableAutoConfiguration(exclude={DataSource ...

  6. JavaScript 中call()、 apply()、 bind()改变this指向理解

    最近开发的过程中遇到了this指向问题,首先想到的是call().apply().bind()三个方法,有些时候这三个方法确实是十分重要,现在我们就把他们的使用方法及异同点讲解一下. 1.每个函数都包 ...

  7. linux实操_shell流程控制

    if判断: 基本语法: if [ 条件判断式 ] then 程序 elif [ 条件判断式 ] then 程序 fi 实例:请编写一个shell程序,如果输入的参数,大于60,则输出“及格了”,如果小 ...

  8. Lua 学习之基础篇八<Lua 元表(Metatabble)&&继承>

    讲到元表,先看一段table的合并动作. t1 = {1,2} t2 = {3,4} t3 = t1 + t2 attempt to perform arithmetic on a table val ...

  9. ADO.Net数据库连接字符串、DbProviderFactory

    一.ADO.Net数据库连接字符串 1.OdbcConnection(System.Data.Odbc) (1)SQL Sever 标准安全:" Driver={SQL Server}; S ...

  10. 5-修改windows的远程桌面端口3389

    一.注意点 1.Windows远程桌面端口默认是3389,是一个高危端口,所以需要改为其他的: 2.修改完注册表后,要重启机器,才能生效: 二.操作步骤 1.打开注册表 命令:regedit 2.进入 ...