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. MQ学习(二)----ActiveMQ简介(转)

    1.  什么是ActiveMQ ActiveMQ是一种开源的,实现了JMS1.1规范的,面向消息(MOM)的中间件,为应用程序提供高效的.可扩展的.稳定的和安全的企业级消息通信.ActiveMQ使用A ...

  2. BZOJ 1901: Zju2112 Dynamic Rankings( 树状数组套主席树 )

    裸的带修改主席树.. 之前用BIT套Splay( http://www.cnblogs.com/JSZX11556/p/4625552.html )A过..但是还是线段树好写...而且快(常数比平衡树 ...

  3. Struts学习之文件上传

    * 单文件上传:        * 在动作类action中声明相关属性:            * 在动作类action中,要声明与页面中表单name属性同名的属性,同名的属性的类型是File类型:  ...

  4. HDU2955-Robberies

    描述: The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usual ...

  5. Java Buffer

    1.1 NIO Buffers - Class java.nio.Buffer NIO data transfer is through the so-called buffers implement ...

  6. break在switch中的使用例子

    /* Name:break在switch中的使用例子 Copyright: By.不懂网络 Author: Yangbin Date:2014年2月21日 03:16:52 Description:以 ...

  7. JAVA并发,CountDownLatch使用

    该文章转自:http://www.itzhai.com/the-introduction-and-use-of-a-countdownlatch.html CountDownLatch 1.类介绍 一 ...

  8. QTabWiget Change Color 改变颜色(每个QWidget都有一个自己的调色板palette,设置它的颜色,然后setAutoFillBackground即可)

    Qt中的QTabWiget 类提供了一个便签控件,但是这个控件默认初始化的颜色是白色,和原窗口的颜色不同,看起来非常的违和,所以我们希望将其的背景颜色设为当前窗口的背景颜色.我们所要做的就是先将应用程 ...

  9. CCNP路由实验(3) -- 路由控制

    1.用distribute-list过滤路由在不同协议里的用法 在RIP里 在EIGRP里 在OSPF里 只接收奇数路由 只接收偶数路由 只接收被4整除的路由2.offset-list在不同协议里的用 ...

  10. Windows Azure Camp---漫步云端,创意无限

    不再需要一系列繁杂的网银密码,一键搞定所有的支付:与朋友约会时通过实时分享地理位置迅速找到对方,这些都可以在WindowsAzure平台得以实现.在刚刚结束的2013年微软学生夏令营中,来自全国30所 ...