# 集合算法

functional
algorithm

1.set_union 交集
2.set_difference 差集
3.set_intersection 交集
4. set_symmetric_difference 对称差集

## set_union(并集)

``````#include<iostream>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>

using  namespace std;

int main()
{
vector<int> date1{ 1, 2, 3, 4, 7, 8 };
vector<int> date2{ 5, 6, 7, 8 };

//1. set_union  并集算法
//可以放到另一个容器中，也可以直接使用输出流打印出来

set_union(date1.begin(), date1.end(), date2.begin(), date2.end(), ostream_iterator<int>(cout, " "));

return 0;
}
``````

## set_difference(差集)

``````#include<iostream>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>

using  namespace std;

int main()
{
vector<int> date1{ 1, 2, 3, 4, 7, 8 };
vector<int> date2{ 5, 6, 7, 8 };

//2.set_difference 差集算法
set_difference(date1.begin(), date1.end(), date2.begin(), date2.end(), ostream_iterator<int>(cout, " "));

return 0;
}
``````

## set_intersection(交集)

``````#include<functional>
#include<algorithm>
#include<string>
#include<vector>

using  namespace std;

int main()
{
vector<int> date1{ 1, 2, 3, 4, 7, 8 };
vector<int> date2{ 5, 6, 7, 8 };

//3.交集
set_intersection(date1.begin(), date1.end(), date2.begin(), date2.end(), ostream_iterator<int>(cout, " "));
cout << endl;

return 0;
}
``````

## set_symmetric_difference(对称差集)

``````#include<iostream>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>

using  namespace std;

int main()
{
vector<int> date1{ 1, 2, 3, 4, 7, 8 };
vector<int> date2{ 5, 6, 7, 8 };

//4.对称差集算法 set_symetric_difference
set_symmetric_difference(date1.begin(), date1.end(), date2.begin(), date2.end(),ostream_iterator<int>(cout," "));
cout << endl;

return 0;
}
``````

THE END