#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
bool bothEvenOrOdd(int elem1, int elem2)
{
return elem1 % 2 == elem2 % 2;
}
int main()
{
vector<int> ivec;
list<int> ilist;
for (int i = 1; i <= 7; ++i)
ivec.push_back(i);
for (int i = 3; i <= 9; ++i)
ilist.push_back(i);
for (vector<int>::iterator iter = ivec.begin(); iter != ivec.end(); ++iter)
cout << *iter << ' ';
cout << endl;
for (list<int>::iterator iter = ilist.begin(); iter != ilist.end(); ++iter)
cout << *iter << ' ';
cout << endl;
if (equal(ivec.begin(), ivec.end(), ilist.begin())) // ivec.begin()和ivec.end()区间与 ilist.begin()到最后这两个区间的数字进行比较,
cout << "这两个区间相等" << endl;
else
cout << "这两个区间不相等" << endl;
if (equal(ivec.begin(), ivec.end(), ilist.begin(), bothEvenOrOdd))
{
cout << "这两个区间是奇数对应奇数,偶数对应偶数" << endl;
}
else
cout << "这两个区间不是奇数对应奇数,偶数不对应偶数" << endl;
cout << endl;
return 0;
}
区间比较equal
最新推荐文章于 2019-08-07 20:15:47 发布