stl系列(11):求并集

STL算法中的set_union可以求两个集合的并集,示例代码如下:

#include <algorithm>
#include <vector>

using namespace std;
int main()
{
	vector<int> a,b;
	for(int i=0; i<100; i++)
	{
		a.push_back(i);
		b.push_back(i+20);
	}
	vector<int> c(200);
	vector<int>::iterator it = set_union(a.begin(), a.end(), b.begin(),b.end(),c.begin());
	c.resize(it-c.begin());

	int d;
	cin>>d;
	return 0;
}


猜你喜欢

转载自blog.csdn.net/xiaoshuying/article/details/45041713