#include<iostream>
#include<stdio.h>
#include<list>
#include<algorithm> //set_union求并集
using namespace std; template<class T>
void Print(T List)
{
class T::iterator iter;
for(iter=List.begin(); iter!=List.end(); iter++)
printf("%d ", *iter);
printf("\n");
}
int main()
{ list<int> List_A;
list<int> List_B; for(int i=; i<; i++)
{ List_A.push_back(i);
}
//printf("Enter some integers into List_B:\n");
for(int i=; i<; i++)
{ List_B.push_back(i);
} List_A.sort();
List_B.sort(); list<int> List_C();
//不能将操作后的结果重新放入List_A或者List_B.如果非要如此,可以设一中间变量List_C,先将结果存储至List_C,然后List_A = List_C
//merge(List_A.begin(), List_A.end(), List_B.begin(), List_B.end(), List_C.begin()); //合并
set_union(List_A.begin(), List_A.end(), List_B.begin(), List_B.end(), List_C.begin());//并集
//set_difference(List_A.begin(), List_A.end(), List_B.begin(), List_B.end(), List_C.begin());//差集
//set_symmetric_difference(List_A.begin(), List_A.end(), List_B.begin(), List_B.end(), List_C.begin());//对称差
//set_intersection(List_A.begin(), List_A.end(), List_B.begin(), List_B.end(), List_C.begin());//交集 printf("List_A contains:\n");
Print(List_A);
printf("List_B contains:\n");
Print(List_B);
printf("List_C contains:\n");
Print(List_C);
system("pause");
return ; }

C++ 求向量的交集、并集、差集的更多相关文章

  1. Python 求两个文本文件以行为单位的交集 并集 差集

    Python 求两个文本文件以行为单位的交集 并集 差集,来代码: s1 = set(open('a.txt','r').readlines()) s2 = set(open('b.txt','r') ...

  2. 如何求ArrayList集合的交集 并集 差集 去重复并集

    需要用到List接口中定义的几个方法: addAll(Collection<? extends E> c) :按指定集合的Iterator返回的顺序将指定集合中的所有元素追加到此列表的末尾 ...

  3. (java/javascript) list 交集 并集 差集 去重复并集

    java list 交集 并集 差集 去重复并集 package com; import java.util.ArrayList; import java.util.Iterator; import ...

  4. spark之交集并集差集拉链

    spark之交集并集差集拉链 def main(args: Array[String]): Unit = { val sparkConf = new SparkConf().setMaster(&qu ...

  5. java 两个list 交集 并集 差集 去重复并集

    前提需要明白List是引用类型,引用类型采用引用传递. 我们经常会遇到一些需求求集合的交集.差集.并集.例如下面两个集合: List<String> list1 = new ArrayLi ...

  6. SQL求 交集 并集 差集

    故事是这样的….. 故事情节: 表 tb_test 有两列, colA , colB; 求 colA , colB 的并交差集… -- 计算并集 SELECT DISTINCT colB FROM t ...

  7. js求对象数组的交集/并集/差集/去重

    1.求交集 var arr1 = [{name:'name1',id:1},{name:'name2',id:2},{name:'name3',id:3}]; var arr1Id = [1,2,3] ...

  8. js求两个数组的交集|并集|差集|去重

    let a = [1,2,3], b= [2, 4, 5]; 1.差集 (a-b 差集:属于a但不属于b的集合)  a-b = [1,3] (b-a 差集:属于b但不属于a的集合)  b-a = [4 ...

  9. stl set求交集 并集 差集

    #include <iostream>#include <set> using namespace std; typedef struct tagStudentInfo{  i ...

随机推荐

  1. tyvj 1423 GF和猫咪的玩具

    传送门 解题思路 题目比较水,floyd求出最短路取个最小值即可.结果joyoi时限写错了..好像只有0ms才能过??突然发现加了快读就T不加就A,数据在10000以下的还是scanf快啊. 代码 # ...

  2. nginx源码分析线程池详解

    nginx源码分析线程池详解 一.前言     nginx是采用多进程模型,master和worker之间主要通过pipe管道的方式进行通信,多进程的优势就在于各个进程互不影响.但是经常会有人问道,n ...

  3. linux源码安装

    以安装xxx.tar.gz为例: 源码存放位置:/usr/local/src/ 安装路径:/usr/local/xxx/ 配置文件存放位置:/usr/local/xxx/etc/ 可执行文件存放位置: ...

  4. windows下maven的安装配置

    什么是maven Maven是基于POM(工程对象模型),通过一小段描述来对项目的代码.报告.文件进管理的工具. Maven是一个跨平台的项目管理工具,它是使用java开发的,它要依赖于jdk1.6及 ...

  5. ML面试1000题系列(41-50)

    本文总结ML面试常见的问题集 转载来源:https://blog.csdn.net/v_july_v/article/details/78121924 41. #include和#include“fi ...

  6. new操作符实现过程

    var obj = new Object(); //创建新对象 一. new是干嘛的? new操作符用来生成一个新的对象, 它后面必须跟上一个函数(否则, 会抛出TypeError异常), 这个函数就 ...

  7. LintCode刷题笔记-- Distinct Subsequences

    标签:动态规划 题目描述: Given a string S and a string T, count the number of distinct subsequences of T in S. ...

  8. js this工作原理

    js中的this是个很妙的东西,你经常不知道它到底在指向谁,又是谁在调用它. 通用判断方法: 1.this总是指向它的直接调用者 var a={ user:'Artimis', fn:function ...

  9. 来自 Spring Cloud 官方的消息,Spring Cloud Alibaba 即将毕业

    2019 年 7 月 24 日晚,Spring Cloud 官方发布公告: 仓库迁移是官方决定 Spring Cloud Alibaba 即将毕业 根据官方最新的发版规则,我们会把孵化器中的 Spri ...

  10. pandas使用手册

    工欲善其事必先利其器,在使用Python做数据挖掘和数据分析时,一大必不可少的利器就是Pandas库了.pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的,其纳入了大量库 ...