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的使用例子,让我惊讶不已.为了 ...
随机推荐
- Objective-c——UI基础开发第九天(QQ好友列表)
一.知识点: 1.双模型的嵌套使用 2.Button的对齐方式 3.优化UITableView的加载 4.layoutSubview的使用 5.cell的折叠代理 二.双模型的嵌套定义: 注意是将se ...
- hbase(ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet)
今天启动clouder manager集群时候hbase list出现 (ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException ...
- php文件遍历
<?php $dirname="shangchuan/uploads"; echo $dirname."共计大小为:".toSize(dirsize($d ...
- 文件的搜寻【转vbird】
which (寻找『运行档』) [root@www ~]# which [-a] command 选项或参数: -a :将所有由 PATH 目录中可以找到的命令均列出,而不止第一个被找到的命令名称 分 ...
- git checkout 和 git checkout --merge <branch_name>使用
一.git checkout //查看当前分支$ git branch master *t2 testing //checkout会覆盖当前工作区文件和覆盖暂存区内容,所以发现分支有未提交的警告,执行 ...
- 11g新特性与12c新特性
1. 11g新特性概图 管理新特性> 开发新特性> 2. 12c 新特性概图
- lucene 专业名词作用整理
是否切词:对关键词是否切分,举例,姓名域的一个值:"张三" , 是否切分成"张"."三"等等多个term. 是否索引:建立索引的时候是否对该 ...
- NoSQL之Redis高级实用命令详解--安全和主从复制
Android IOS JavaScript HTML5 CSS jQuery Python PHP NodeJS Java Spring MySQL MongoDB Redis NOSQL Vim ...
- eclipse中新建maven项目-转
http://huxiaoheihei.iteye.com/blog/1766986 博客分类: maven maven maven是个项目管理工具,集各种功能于一身,下面介绍maven web项目 ...
- Request.RequestContext.RouteData.Values获取不到参数值
Request.RequestContext.RouteData.Values是获取路由配置中参数的值. 如过路由配置是: public static void RegisterRoutes(Rout ...