#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
//v1与v2的差集 不同于 v2与v1的差集
void test2101()
{
vector<int> v1, v2;
vector<int> vTarget;
for (int i = 0; i < 10; i++)
{
v1.push_back(i);
v2.push_back(i + 5);
}
vTarget.resize(max(v1.size(), v2.size()));
//v1与v2的差集:
vector<int>::iterator itEnd1 = set_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), vTarget.begin());
for (vector<int>::iterator it = vTarget.begin(); it != itEnd1; it++)
{
cout << (*it) << " ";
}
cout << endl;
//v2与v1的差集:
vector<int>::iterator itEnd2 = set_difference(v2.begin(), v2.end(), v1.begin(), v1.end(), vTarget.begin());
for (vector<int>::iterator it = vTarget.begin(); it != itEnd2; it++)
{
cout << (*it) << " ";
}
cout << endl;
}
int main()
{
test2101();
system("pause");
return 0;
}
网友评论