STL algorithm算法mismatch(37)
mismatch原型:
std::mismatch
| equality (1) |
template <class InputIterator1, class InputIterator2> |
|---|---|
| predicate (2) |
template <class InputIterator1, class InputIterator2, class BinaryPredicate> |
该函数是用来查找两个序列中第一对不匹配的元素。第一个序列为[first1.last1),第二个序列从first2開始。
比如:
序列1:1,3,5,7,9
序列2:1,3,8,8,9
第一对不匹配的元素为(5,8)
假设第一个序列和第二个序列的前部全然同样,比如
1,2,3,4
1,2,3,4,5
则返回make_pari(last1,5);
使用operator==来进行比較。
行为类似于:
template <class InputIterator1, class InputIterator2>
pair<InputIterator1, InputIterator2>
mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2 )
{
while ( (first1!=last1) && (*first1==*first2) ) // or: pred(*first1,*first2), for version 2
{ ++first1; ++first2; }
return std::make_pair(first1,first2);
}
一个简单的样例:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void mmismatch(){
vector<int> vi{3,5,4,1};
vector<int> v2{3,5,5,1};
cout<<"vi=";
for(int i:vi)
cout<<i<<" ";
cout<<endl;
cout<<"v2=";
for(int i:v2)
cout<<i<<" ";
cout<<endl;
auto it=mismatch(vi.begin(),vi.end(),v2.begin());
cout<<"*it.first="<<*it.first<<" ,*it.second="<<*it.second<<endl; vector<int> v3{3,5,4,1,6};
cout<<"v3=";
for(int i:v3)
cout<<i<<" ";
cout<<endl;
auto it2=mismatch(vi.begin(),vi.end(),v3.begin());
cout<<"*it2.first="<<*it2.first<<" ,*it2.second="<<*it2.second<<endl; }
执行结果:
——————————————————————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,能够在以下留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我改动,更好的分享给大家,谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双
Email:coderguang@gmail.com
2014-9-19
于GDUT
——————————————————————————————————————————————————————————————————
STL algorithm算法mismatch(37)的更多相关文章
- STL algorithm算法is_permutation(27)
is_permutation原型: std::is_permutation equality (1) template <class ForwardIterator1, class Forwar ...
- STL algorithm算法merge(34)
merge原型: std::merge default (1) template <class InputIterator1, class InputIterator2, class Outpu ...
- STL algorithm算法lower_bound和upper_bound(31)
lower_bound原型: function template <algorithm> std::lower_bound default (1) template <class F ...
- STL algorithm算法minmax,minmax_element(36)
minmax原型: std::minmax C++11 C++14 default (1) template <class T> pair <const T&,const T ...
- STL algorithm算法min,min_element(35)
min样板: std::min C++98 C++11 C++14 default (1) template <class T> const T& min (const T& ...
- STL algorithm算法max,max_elements(33)
max原型: std::max C++98 C++11 C++14 default (1) template <class T> const T& max (const T& ...
- STL algorithm算法mov,move_backward(38)
move原型: std::move template <class InputIterator, class OutputIterator> OutputIterator move (In ...
- STL algorithm算法make_heap和sort_heap(32)
make_heap原型: std::make_heap default (1) template <class RandomAccessIterator> void make_heap ( ...
- STL algorithm算法lexicographical_compare(30)
lexicographical_compare原型: std::lexicographical_compare default (1) template <class InputIterator ...
随机推荐
- VC++学习之网络编程中的套接字
VC++学习之网络编程中的套接字 套接字,简单的说就是通信双方的一种约定,用套接字中的相关函数来完成通信过程.应用层通过传输层进行数据通信时,TCP和UDP会遇到同时为多个应用程序进程提供并发服务的问 ...
- Java基础之静态变量
public class StaticVariable { public static void main(String[] args) { Person p1 = new Person(); Per ...
- javascript小练习—点击将DIV变成红色(通过for循环遍历)
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- jQuery入门第二
element选择器 在文具盒中,有铅笔.钢笔和水彩笔,类似于页面中的<div>.<span>各个元素,虽然同属于一个容器,但有各自的功能,jQuery中可以根据元素名查找元 ...
- python进阶6 HTTP协议客户端实现
httplib 1.httplib 是 python中http 协议的客户端实现,可以使用该模块来与 HTTP 服务器进行交互. httplib的内容不是很多,也比较简单.以下是一个非常简单的例子,使 ...
- easyui-layout中的收缩层无法显示标题问题解决
先看问题描述效果图片: 如上,我的查询条件是放在layout下面的一个可收缩层中,初始是收缩的,title显示不出来的话对使用者很不方便,代码如下: <div id="__MODULE ...
- 什么是epoll
什么是epoll epoll是什么?按照man手册的说法:是为处理大批量句柄而作了改进的poll.当然,这不是2.6内核才有的,它是在2.5.44内核中被引进的(epoll(4) is a new A ...
- 关于cvScalar的那些事
CvScalar 可存放在1-,2-,3-,4-TUPLE类型的捆绑数据的容器 该函数包含4个浮点成员,可以用来表示B(Blue),G(Green),R(Red),Alpha(表示图像的透明度) ty ...
- BaseAdapter使listview设置不同背景图片并添加selector
前段时间为了实现根据item不同的内容实现不同的背景色google了好久只找到了个隔行换色,通过自定义SimpleAdapter终于实现了此功能,但是定义了selector并没有触发点击效果.今天重新 ...
- 关于typedef之四种用途 和 两个陷进
typedef用来声明一个别名,typedef后面的语法,是一个声明.本来笔者以为这里不会产生什么误解的,但结果却出乎意料,产生误解的人 不在少数.罪魁祸首又是那些害人的教材.在这些教材中介绍type ...