C++ STL 已序区间查找算法
#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 已序区间查找算法的更多相关文章
- STL学习笔记(已序区间算法)
针对已序区间执行的算法,执行前提是源区间必须在某个排序准则下已序. 搜寻元素(Searching) 1.检查某个元素是否存在 bool binary_search(ForwardIterator be ...
- STL_算法_查找算法(lower_bound、upper_bound、equal_range)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n))) 已序区间查找算法 lower_bound() //找第一个符合的 ...
- STL_算法_查找算法(binary_search、includes)
C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n))) 已序区间查找算法 binary_search //二分查 ...
- C++ STL之查找算法
C++STL有好几种查找算法,但是他们的用法上有很多共同的地方: 1.除了binary_search的返回值是bool之外(查找的了返回true,否则返回false),其他所有的查找算法返回值都是一个 ...
- 从零开始学C++之STL(四):算法简介、7种算法分类
一.算法 算法是以函数模板的形式实现的.常用的算法涉及到比较.交换.查找.搜索.复制.修改.移除.反转.排序.合并等等. 算法并非容器类型的成员函数,而是一些全局函数,要与迭代器一起搭配使用. 算法的 ...
- STL_算法_查找算法(find、find_if)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) 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 ...
随机推荐
- 06 Windows编程——设备句柄 和 WM_PAINT消息
windows程序在现实方式上属于图形方式,和文字方式的显示,有显著的不同. 什么是设备句柄,如何获取 使用统一的数据结构表示某一设备,这个结构就是设备句柄. 源码 #include<Windo ...
- 关于Python的第一行语句
通常在脚本语言的第一行会看到#!/usr/bin/env python 与 #!/usr/bin/python其中之一,这两句话的目的都是指出你的python文件用什么可执行程序去运行它. #!/us ...
- 【shell】ping加时间戳回复
ping 192.168.2.1 -c 10 | awk '{ print $0"\t" strftime("%H:%M:%S",systime()) } ' ...
- NoClassDefFoundError: org/springframework/boot/bind/RelaxedDataBinder
今天启动springboot的时候发现一个类不能注入RelaxedDataBinder,发现是没有相应的jar包,原因是在版本2.x之后删除了包.所以只要在之后的引用版本中换成2.x之后即可. 查看p ...
- 按下开机键,Linux做了什么?
作者:Vamei 来源:见文末 计算机开机是一个神秘的过程.我们只是按了开机键,就看到屏幕上的进度条或者一行行的输出,直到我们到达登录界面.然而,计算机开机又是个异常脆弱的过程,我们满心期望的登录界面 ...
- 1114 CSS基础
目录 CSS入门 标签设置长宽 1.字体样式 1.1 字体类型 font-family 1.2 字体大小 font-size 1.3 字体颜色 color 1.4 字体粗细 font-weight 1 ...
- 深入了解jQuery之链式结构
本文是在阅读了Aaron艾伦的jQuery源码解析(地址:http://www.imooc.com/learn/172)后的个人体会以及笔记.在这里感谢艾伦老师深入浅出的讲解!! 1 什么是链式? 先 ...
- sql 存储过程记录
-- exec sp_helptext add_book1 CREATE proc add_book1 --创建存储过程 @DocCode VARCHAR() --创建参数 as BEGIN INSE ...
- 深入理解Java输入输出流
Java.io包的File类,File类用于目录和文件的创建.删除.遍历等操作,但不能用于文件的读写. Java 对文件的写入和读取涉及到流的概念,写入为输出流,读取为输入流.如何理解流的概念呢?可以 ...
- 路由器配置——基于链路的OSPF的MD5口令认证
一.实验目的:掌握基于链路的OSPFMD5口令认证 二.拓扑图: 三.具体步骤配置: (1)R1路由器的配置 Router>enable Router#configure terminal En ...