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 ...
随机推荐
- 最最常用的RAID
若转载请于明显处标明出处:http://www.cnblogs.com/kelamoyujuzhen/p/8980696.html RAID stands for Redundant Array of ...
- 补充:HTML标签和CSS
角标标签: 上角标:sup 下角标:sub <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...
- 如何利用while语句根据用户输入要求打印菱形图案
需求:如何利用while语句根据用户输入要求打印菱形图案 diamond.py代码如下: x=int(input('Please input number: ')) i=1 j=1 while i&l ...
- idou老师教你学Istio 08: 调用链埋点是否真的“零修改”?
本文将结合一个具体例子中的细节详细描述Istio调用链的原理和使用方式.并基于Istio中埋点的原理解释来说明:为了输出一个质量良好的调用链,业务程序需根据自身特点做适当的修改,即并非官方一直在说的完 ...
- watch 监控的新旧值一致问题处理
watch 监控的新旧值一致问题处理 http://www.imooc.com/article/details/id/286654
- linux实操_rpm包和yum包
rpm包的简单查询指令: 查询已安装的rpm列表 rpm -qa | grep xxx 查询火狐浏览器 查询安装的rpm包软件的信息 查询rpm软件包的文件安装在哪里 查询文件属于哪个软件包 卸载rp ...
- Python+request+ smtplib 测试结果html报告邮件发送(上)《五》
此方法通用适合所有邮箱的使用,只需注意几个点,如下: QQ邮箱.其他非QQ邮箱的写法,区别点如下: #--------------------------使用腾讯企业邮箱作为发件人的操作如下----- ...
- python 中的 字符串 列表 元祖 字典
str 1 格式化输出 %法 第一种 %s+tuple %d+tuple name = input('请输入你的姓名:') age = input('请输入你的年龄:') hobby = input( ...
- 2019牛客多校第五场generator2——BSGS&&手写Hash
题目 几乎原题 BZOJ3122题解 分析 先推一波公式,然后除去特殊情况分类讨论,剩下就是形如 $a^i \equiv b(mod \ p)$ 的方程,可以使用BSGS算法. 在标准的BSGS中,内 ...
- Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) C. Save the Nature【枚举二分答案】
https://codeforces.com/contest/1241/problem/C You are an environmental activist at heart but the rea ...