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 ...
随机推荐
- Computer Vision_18_Image Stitching:Automatic Panoramic Image Stitching using Invariant Features——2007
此部分是计算机视觉部分,主要侧重在底层特征提取,视频分析,跟踪,目标检测和识别方面等方面.对于自己不太熟悉的领域比如摄像机标定和立体视觉,仅仅列出上google上引用次数比较多的文献.有一些刚刚出版的 ...
- Tcp/IP协议详讲
TCP/IP协议分层详解 目录 TCP/IP 和 ISO/OSI TCP/IP分层模型 数据的封装与分用 其他相关概念 TCP/IP 通信传输流 负责传输的 IP 协议 正文 回到顶部 TCP/IP ...
- No PostCSS Config found in报错解决
前情提要]日前本人将本地项目上传GitHub之后,然后再clone到本地,运行是报错:Error: No PostCSS Config found in... 项目在本地打包运行的时候不报错,上传到 ...
- win服务器 解决apache 80端口被占用问题
是系统的服务占用了80端口,所以要么结束系统服务,要么修改apache端口. PID4的服务是World Wide Web Publishing Service 这里选择结束这个系统服务,运行serv ...
- springboot mybatis 的SQL异常不输出错误到控制台问题排查
项目中使用springboot集成 mybatis,运行过程中查询SQL列在表中不存在,但系统不输出任何错误到控制台 但SQL是打印的,只是没有任何异常信息 将SQL复制出来到数据库中运行,才发现错误 ...
- Java8-Executors-No.02
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import ...
- BZOJ 1778: [Usaco2010 Hol]Dotp 驱逐猪猡 (高斯消元)
题面 题目传送门 分析 令爆炸概率为PPP.设 f(i)=∑k=0∞pk(i)\large f(i)=\sum_{k=0}^{\infty}p_k(i)f(i)=∑k=0∞pk(i),pk(i)p ...
- django post请求 403错误解决方法
--摘 第一次用Django做项目,遇到了很多问题. 今天遇到的问题是Django在处理post请求时多次出现403错误. 我先描述一下问题出现的环境:我用Django写了一个web服务端,姑且称它为 ...
- 从入门到精通djang Django
http://docs.30c.org/djangobook2/ 推荐大家一本书 特别用用 中文版的 哦
- 六十.完全分布式 、 节点管理 、 NFS网关
1.安装与部署 对mapred和yarn文件进行配置 验证访问Hadoop 在六十准备好的环境下给master (nn01)主机添加ResourceManager的角色,在node1,node2, ...