c++ STL find search
#include <iostream>
#include <algorithm>
#include <deque>
#include <list>
#include <vector>
#include <functional>
using namespace std;
//二元谓词
bool isEven(int elementParam, bool even)
{
if (even)
{
return elementParam % 2 == 0;
}
else
{
return elementParam % 2 == 0;
}
}
int main()
{
deque<int> deque1;
list<int> list1;
for (int k=0;k<10;k++)
{
deque1.insert(deque1.end(),k);
}
for (int k = 1; k<11; k++)
{
deque1.insert(deque1.end(), k);
}
for (int k = 3; k<10; k++)
{
deque1.insert(deque1.end(), k);
}
deque<int>::iterator deque_iter;
for (deque_iter = deque1.begin();deque_iter != deque1.end();++deque_iter)
{
cout << *deque_iter << " ";
}
cout << endl;
for (int k=4;k<10;k++)
{
list1.push_back(k);
}
list<int>::iterator list_iter1;
for (list_iter1 = list1.begin();list_iter1 != list1.end();++list_iter1)
{
cout << *list_iter1 << " ";
}
cout << endl;
deque<int>::iterator deque_iter1;
deque_iter1 = search(deque1.begin(), deque1.end(), list1.begin(), list1.end());
while (deque_iter1 != deque1.end())
{
cout << "find ! element position:" <<distance(deque1.begin(),deque_iter1)+1<< endl;
++deque_iter1;
deque_iter1 = search(deque_iter1, deque1.end(), list1.begin(), list1.end());
}
cout << "------------------------------------------------" << endl;
vector<int> vector1;
for (int k=0;k<10;k++)
{
vector1.push_back(k);
}
vector1.push_back(10);
vector1.push_back(12);
vector1.push_back(14);
vector<int>::iterator vector_iter1;
for (vector_iter1 = vector1.begin();vector_iter1 != vector1.end();++vector_iter1)
{
cout << *vector_iter1 << " ";
}
cout << endl;
bool checkEventArgs[3] = { true,false,true };
vector<int>::iterator vector_iter2;
vector_iter2 = search(vector1.begin(), vector1.end(),checkEventArgs,checkEventArgs+3, isEven);
if (vector_iter2 != vector1.end())
{
cout << "find:" << *vector_iter2 << endl;
}
else
{
cout << "not find.." << endl;
}
system("pause");
return 0;
}
=====================================================
0 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10 3 4 5 6 7 8 9
4 5 6 7 8 9
find ! element position:5
find ! element position:14
find ! element position:22
------------------------------------------------
0 1 2 3 4 5 6 7 8 9 10 12 14
find:10
请按任意键继续. . .

c++ STL find search的更多相关文章
- stl binary search
stl binary search */--> pre { background-color: #2f4f4f;line-height: 1.6; FONT: 10.5pt Consola,&q ...
- STL之search
描述 使用STL中的search函数,判断一个序列是否是另一个序列的子序列. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() { vector<int> ...
- leetcode@ [34] Search for a Range (STL Binary Search)
https://leetcode.com/problems/search-for-a-range/ Given a sorted array of integers, find the startin ...
- C++ STL Binary search详解
一.解释 以前遇到二分的题目都是手动实现二分,不得不说错误比较多,关于返回值,关于区间的左闭右开等很容易出错,最近做题发现直接使用STL中的二分函数方便快捷还不会出错,不过对于没有接触过的同学,二分函 ...
- STL 简介,标准模板库
这篇文章是关于C++语言的一个新的扩展--标准模板库的(Standard Template Library),也叫STL. 当我第一次打算写一篇关于STL的文章的时候,我不得不承认我当时低估了这个话 ...
- STL中list用法
本文以List容器为例子,介绍了STL的基本内容,从容器到迭代器,再到普通函数,而且例子丰富,通俗易懂.不失为STL的入门文章,新手不容错过! 0 前言 1 定义一个list 2 使用list的成员函 ...
- STL list链表的用法详解
本文以List容器为例子,介绍了STL的基本内容,从容器到迭代器,再到普通函数,而且例子丰富,通俗易懂.不失为STL的入门文章,新手不容错过! 0 前言 1 定义一个list 2 使用list的成员函 ...
- list用法详解
在这里感谢大牛们的奉献!此致敬礼! 本文转载自百度文库.作者如下.其中下面的count, count_if等函数的使用有些陈旧,如在编译时遇到问题,请百度. 标准模板库(STL)介绍 作者:Scott ...
- AwesomePerfCpp 性能优化
Contents Talks Articles Sites/Blogs Tools Libraries Books About Talks 2013: Going Native 2013 - Andr ...
随机推荐
- 《数据结构与算法之美》 <03>数组:为什么很多编程语言中数组都从0开始编号?
提到数组,我想你肯定不陌生,甚至还会自信地说,它很简单啊. 是的,在每一种编程语言中,基本都会有数组这种数据类型.不过,它不仅仅是一种编程语言中的数据类型,还是一种最基础的数据结构.尽管数组看起来非常 ...
- I2C总线、设备、驱动
I2C总线.设备.驱动 框架 I2C驱动框架可分为3个部分,分别是:I2C核心层.I2C总线驱动层(适配器层)以及I2C设备驱动层: I2C核心层 提供了统一的I2C操作函数,主要有两套函数smbus ...
- python-----多进程笔记
多进程笔记: 在Python中多进程的创建方式对比: 1.在Python中,可以通过os.fork()创建子进程,但是这种方式智能在'linux'和'unix'以及'mac'下面使用,不能跨平台,所以 ...
- Python 文件操作(1)
今天大佬给了个A文件给我,里面存放了机密数据. 什么机密数据??? 有帅哥的联系方式吗? 赶紧打开来看一下 1.open() 函数基本版 Python大佬有个内置开文件的函数open(), 专门开文件 ...
- python3 虚拟环境
一.python中的虚拟环境 1.虚拟环境:局部的,独立的python环境,完全模拟系统全局python环境的使用 二.安装 http://virtualenv.pypa.io/en/latest/u ...
- 题解 [ZJOI2010]基站选址
题解 [ZJOI2010]基站选址 题面 解析 首先考虑一个暴力的DP, 设\(f[i][k]\)表示第\(k\)个基站设在第\(i\)个村庄,且不考虑后面的村庄的最小费用. 那么有\(f[i][k] ...
- JS BOM基础 全局对象 window location history screen navigator
全局变量声明的两种方式:1,window.变量名=值;2,var 变量名=值; 全局函数声明的两种方式:1,window.函数名=function(){}2,function 函数名=function ...
- Educational Codeforces Round 72 (Rated for Div. 2) C题
C. The Number Of Good Substrings Problem Description: You are given a binary string s (recall that a ...
- 007_STM32程序移植之_多通道ADC转换
1. 测试环境:STM32C8T6 2. 测试:使用DMA进行多通道ADC转换 3. 描述:用 ADC 连续采集 12 路模拟信号,并由 DMA 传输到内存.ADC 配置为扫描 并且连续转换模式,AD ...
- jumpserver官方手动安装
测试环境 CPU: 64位双核处理器 内存: 4G DDR3 数据库:mysql 版本大于等于 5.6 mariadb 版本大于等于 5.5.6 环境 系统: CentOS 7 IP: 192.168 ...