#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. Netty4实现JTT809对接

    网上的使用的netty版本过老,最近自己接触到这一块,重新写了一个 服务器流程 1,判定报文起始和结束标识 ,2去掉头尾标识进行转义,3,去掉CRC码进行CRC计算,4读取报文头,(5,如果加密则解密 ...

  2. asp.net中gridview控件的一些基本使用方法

    [ 转自苏飞博客]共两篇 (1)菜单目录: GridView无代码分页排序GridView选中,编辑,取消,删除GridView正反双向排序GridView和下拉菜单DropDownList结合Gri ...

  3. phpstorm和ftp搭配使用

    简单使用

  4. Codeforces Round #539 (Div. 1) C. Sasha and a Patient Friend 动态开点线段树

    题解看这里 liouzhou_101的博客园 更简洁的代码看这里: #include <bits/stdc++.h> using namespace std; typedef long l ...

  5. EF非常见错误:EXECUTE 后的事务计数指示 BEGIN 和 COMMIT 语句的数目不匹配

    EF非常见错误:EXECUTE 后的事务计数指示 BEGIN 和 COMMIT 语句的数目不匹配 问题原因: 两个表A\B之间存在外键关系,当插入表A的时候,A的外键B在B表中不存在可以引起这个问题: ...

  6. Codeforces Round #495 (Div. 2) A,B,C

    A题 1.新添加一间酒店,要求酒店离已有的最近的一间酒店的距离恰好等于d 2.最左和最右必定存在合适的两种情况 3.酒店之间的情况就要判断两间酒店间的距离: 小于2d,表示无法在这两间酒店中间找到合适 ...

  7. 007_Linux驱动之_copy_from_user函数

    1. copy_from_user函数的目的是从用户空间拷贝数据到内核空间 2. 解析原型: copy_from_user(void *to, const void __user *from, uns ...

  8. [Luogu] 魔板

    https://www.luogu.org/problemnew/show/P1275 #include <iostream> #include <cstdio> #inclu ...

  9. 外网可以反问lxr

    , 'baseurl_aliases' => 174       [ 'http://172.168.2.4/lxr' 175       , 'http://mydomain/lxr' 176 ...

  10. Simple Problem with Integers(POJ 3486)

                                                                  A Simple Problem with Integers Time Li ...