mismatch原型:

std::mismatch

equality (1)
template <class InputIterator1, class InputIterator2>
pair<InputIterator1, InputIterator2>
mismatch (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2);
predicate (2)
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
pair<InputIterator1, InputIterator2>
mismatch (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, BinaryPredicate pred);

该函数是用来查找两个序列中第一对不匹配的元素。第一个序列为[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)的更多相关文章

  1. STL algorithm算法is_permutation(27)

    is_permutation原型: std::is_permutation equality (1) template <class ForwardIterator1, class Forwar ...

  2. STL algorithm算法merge(34)

    merge原型: std::merge default (1) template <class InputIterator1, class InputIterator2, class Outpu ...

  3. STL algorithm算法lower_bound和upper_bound(31)

    lower_bound原型: function template <algorithm> std::lower_bound default (1) template <class F ...

  4. STL algorithm算法minmax,minmax_element(36)

    minmax原型: std::minmax C++11 C++14 default (1) template <class T> pair <const T&,const T ...

  5. 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& ...

  6. 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& ...

  7. STL algorithm算法mov,move_backward(38)

    move原型: std::move template <class InputIterator, class OutputIterator> OutputIterator move (In ...

  8. STL algorithm算法make_heap和sort_heap(32)

    make_heap原型: std::make_heap default (1) template <class RandomAccessIterator> void make_heap ( ...

  9. STL algorithm算法lexicographical_compare(30)

    lexicographical_compare原型: std::lexicographical_compare default (1) template <class InputIterator ...

随机推荐

  1. js判断微信内置浏览器

    做了一个h5页面来下载app,但如果页面是用微信扫一扫打开的,点击下载按钮下载不了app,原因是微信内置浏览器屏蔽了下载链接.所以增加了检测,如果用户是用微信浏览器打开的,则提示用户使用浏览器打开.那 ...

  2. 关于gradle /Users/xxxx/Documents/workspace/fontmanager/.gradle/2.2.1/taskArtifacts/cache.properties (No such file or directory)报错办法

    转自:http://www.cnblogs.com/raomengyang/p/4367620.html   Android Studio报错: What went wrong: java.io.Fi ...

  3. Cortex-M3动态加载三(模块调用系统函数)

    在我的arm动态加载实验中需要解决一个模块调用系统函数的问题,可以使用以下的一个方法.将系统函数固定在某一段地址空间,然后导出这一块的符号表到符号文件中,要记载的模块link的时候使用这个符号表文件, ...

  4. 移动端的click

    移动端的click 移动端click和touch的关系 搬运 http://segmentfault.com/q/1010000000691822 手指在屏幕上滑动时 各个touch的触发顺序 tou ...

  5. pl sql 无法解析指定的连接标识符

        使用PLSQL Developer时,“ORA-12154: TNS:无法解析指定的连接标识符”问题的一个解决办法< xmlnamespace prefix ="o" ...

  6. 为过程或函数sp_Adduser指定了过多的参数

    前些天写用户注册模块,用存储过程添加用户,一开始就报“为过程或函数sp_Adduser指定了过多的参数”.仔细检查数据层的用户添加函数,结果在为存储过程添加sqlparameter参数的时候,数组给写 ...

  7. Springmvc+Spring+Hibernate搭建方法及实例

    Springmvc+Spring+Hibernate搭建方法及实例  

  8. 疯狂的补贴,广州司机都被Uber触动

    “上线的司机起码少了一半.” 或许是因为长期工作超过12个小时的缘故,39岁的广州人民优步司机姜德昌看上去双眼浮肿,但精力充沛.这是5月8日的一个下午,一周之前他所服务的Uber广州分公司被查封. 据 ...

  9. js导出成excel

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. UVA 11549 Calculator Conundrum (Floyd判圈算法)

    题意:有个老式计算器,每次只能记住一个数字的前n位.现在输入一个整数k,然后反复平方,一直做下去,能得到的最大数是多少.例如,n=1,k=6,那么一次显示:6,3,9,1... 思路:这个题一定会出现 ...