#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template<class Container, class Iterator>
void ShowElement(Container& c, Iterator& itor);
int main()
{
typedef vector<int>::iterator VectorInterator;
vector<int> intValueVector(4);
intValueVector[0] = 1;
intValueVector[1] = 2;
intValueVector[2] = 3;
intValueVector[3] = 4;
vector<int> intValueVector2(3);
intValueVector2[0] = 1;
intValueVector2[1] = 2;
intValueVector2[2] = 3;
VectorInterator first1 = intValueVector.begin();
VectorInterator last1 = intValueVector.end();
VectorInterator first2 = intValueVector2.begin();
if (equal(first1, last1, first2))
cout << "intValueVector == intValueVector2\n";
else
cout << "intValueVector != intValueVector2\n";
pair<VectorInterator, VectorInterator> pi = mismatch(first1, last1, first2);
cout << "First mismatch element in intValueVector = ";
ShowElement(intValueVector, pi.first);
cout << "\n";
cout << "First mismatch element in intValueVector2 = ";
ShowElement(intValueVector2, pi.second);
cout << "\n";
return 0;
}
template<class Container, class Iterator>
void ShowElement(Container& c, Iterator& itor)
{
if (itor != c.end())
{
if (itor != c.begin())
cout << *itor << "\tthe previous element is " << *(itor - 1);
else
cout << "first";
}
else
cout << "last";
}
|