set_union的几个例子
获得两个集合的并集。两个输入序列须保证已排好序。
数组用的时候
// set_union example
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main () {
int first[] = {5,10,15,20,25};
int second[] = {50,40,30,20,10};
vector<int> v(10); // 0 0 0 0 0 0 0 0 0 0
vector<int>::iterator it;
sort (first,first+5); // 5 10 15 20 25
sort (second,second+5); // 10 20 30 40 50
it=set_union (first, first+5, second, second+5, v.begin());
// 5 10 15 20 25 30 40 50 0 0
cout << "union has " << int(it - v.begin()) << " elements.\n";
return 0;
}
set用的时候
// set_union2 example
#include <set>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
set<int> a,b,c;
a.insert(1);
a.insert(6);
a.insert(6);
b.insert(2);
b.insert(6);
b.insert(9);
//最后一个参数若使用c.begin()会产生编译错误assignment of read-only localtion.
set_union(a.begin(), a.end(), b.begin(), b.end(), inserter(c, c.begin()));
copy(c.begin(), c.end(), ostream_iterator <int> (cout, " "));
return 0;
}
vector用的时候
// set_union3 example
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
vector<int> a,b,c;
for(int e=0;e<10;e++)
{
a.push_back(e);
b.push_back(e+5);
}
//最后一个参数若使用c.begin(),运行时会出错“Segmentation fault (core dumped)”.
set_union(a.begin(),a.end(),b.begin(),b.end(),back_inserter(c));
copy(c.begin(), c.end(), ostream_iterator<int> (cout, " "));
return 0;
}
set_union的几个例子的更多相关文章
- STL set_difference set_intersection set_union 操作
以下是STL algorithm的几个函数,使用的条件是有序容器,所以 vector在被sort了之后是可以使用的,set也是可以使用的. set_difference 这个是求得在第一个容器中有,第 ...
- 关于C++里set_intersection(取集合交集)、set_union(取集合并集)、set_difference(取集合差集)等函数的使用总结
文章转载自https://blog.csdn.net/zangker/article/details/22984803 set里面有set_intersection(取集合交集).set_union( ...
- SQLServer地址搜索性能优化例子
这是一个很久以前的例子,现在在整理资料时无意发现,就拿出来再改写分享. 1.需求 1.1 基本需求: 根据输入的地址关键字,搜索出完整的地址路径,耗时要控制在几十毫秒内. 1.2 数据库地址表结构和数 ...
- C#+HtmlAgilityPack+XPath带你采集数据(以采集天气数据为例子)
第一次接触HtmlAgilityPack是在5年前,一些意外,让我从技术部门临时调到销售部门,负责建立一些流程和寻找潜在客户,最后在阿里巴巴找到了很多客户信息,非常全面,刚开始是手动复制到Excel, ...
- REGEX例子
作为REGEX的例子,代码9.3显示了一个给定的文件有多少行,具有给定的模式,通过命令行输入(注:有更有效率的方式来实现这个功能,如Unix下的grep命令,在这里只是给出了另一种方式).这个程序像下 ...
- CSharpGL(25)一个用raycast实现体渲染VolumeRender的例子
CSharpGL(25)一个用raycast实现体渲染VolumeRender的例子 本文涉及的VolumeRendering相关的C#代码是从(https://github.com/toolchai ...
- 简单例子了解View的事件分发
什么是事件分发 我们在写自定义ViewGroup或者自定义View的时候经常要处理用户的点击事件,如果我们的View在最底层,他在很多ViewGroup里面,我们如何让我们的点击事件准确传递到View ...
- 简单的例子了解自定义ViewGroup(一)
在Android中,控件可以分为ViewGroup控件与View控件.自定义View控件,我之前的文章已经说过.这次我们主要说一下自定义ViewGroup控件.ViewGroup是作为父控件可以包含多 ...
- kqueue例子
网络服务器通常都使用epoll进行异步IO处理,而开发者通常使用mac,为了方便开发,我把自己的handy库移植到了mac平台上.移植过程中,网上居然没有搜到kqueue的使用例子,让我惊讶不已.为了 ...
随机推荐
- 所学新知——int、char型转string 类型等
1. 利用stringstream类 定义头文件#include<sstream> 通过 int a; char b; sstream ss,ss1; ss<<a; ss1&l ...
- Codeforces Round #373 (Div. 1)
Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 题意 给一个长为\(n(n \le 2 \times 10^5)\)的小数,每次可以选 ...
- pthread_join和pthread_detach的用法(转)
一:关于join join join是三种同步线程的方式之一.另外两种分别是互斥锁(mutex)和条件变量(condition variable). 调用pthread_join()将阻塞自己,一直到 ...
- HTML5学堂 全新的HTML5/前端技术分享平台
HTML5学堂 全新的HTML5/前端技术分享平台 HTML5学堂是做什么的? HTML5学堂~http://www.h5course.com~由多名热爱H5的讲师们组成的一个组织.致力于构建一个前端 ...
- android解析json包(接口)
package com.http.test; 02 03 04 import org.apache.http.HttpResponse; 05 import org.apache.http ...
- Java 性能优化
http://eclipsesource.com/blogs/2013/01/21/10-tips-for-using-the-eclipse-memory-analyzer/ http://docs ...
- ASM磁盘组空间不足--ORA-15041:DISGROUP DATA space exhausted (生产库案例)
原创作品,出自 "深蓝的blog" 博客,深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/47277715 近日 ...
- C# TextBox 只能输入数字
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { TextBox txt = sender as TextBox ...
- UIview 学习与自定义--ios
UIView *view1=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; view1.backgroundColor=[UI ...
- sql compact 使用EF无法更新的问题?
1.问题一是表中没有主键会报一些莫名其妙的错误. 2.数据库文件被默认复制到了Debug/Release目录,实际调试或运行时发现原有数据库没有被更新.