惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
Apple Machine Learning Research
Apple Machine Learning Research
量子位
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
博客园 - 聂微东
博客园_首页
D
Docker
博客园 - 叶小钗
S
SegmentFault 最新的问题
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
爱范儿
爱范儿
腾讯CDC
罗磊的独立博客
雷峰网
雷峰网
博客园 - Franky

博客园 - PKICA

c++ unordered_map‌底层实现 单片机 MCU,嵌入式,MPU,DSP,FPGA,PLC 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 rust线程-std::thread::park和unpark 配合Builder实现轻量级的线程挂起与唤醒 rust自定义线程属性std::thread::Builder rust线程 rust关联函数 rust高并发设计实践进阶 rust高并发设计实践 rust性能优化与安全边界 联合体union在rust和C语言中有什么区别 rust并发与异步编程 如何预防rust不良的代码设计总结 rust类型系统与零成本抽象 rust内存模型 告别大显存依赖!用 Rust 新一代深度学习框架 Burn 打造纯 CPU 文本分类推理引擎 rust类型系统标记 编译配置解答 git实用命令
C++ STL求两个集合交集差集
PKICA · 2026-04-08 · via 博客园 - PKICA
/** @file  arrInteraction.cpp
*  @note     All Right Reserved.
*  @brief
*  @author 
*  @date   2020/4/15
*  @note   
*  @history
*  @warning
*/

#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <assert.h>
using namespace std;


bool vecCmp(const int &num1, const int &num2)
{
    if(num1 < num2) return true;
    return false;
}

int main()
{
     std::vector<int> v1{ 1,2,3,4,5,6,7,8 };
     std::vector<int> v2{ 5,  7,  9,10 };
     std::sort(v1.begin(), v1.end(), vecCmp);
     std::sort(v2.begin(), v2.end(), vecCmp);
     
     cout << "v1: ";
     for(auto &v1elem: v1)
     {
         cout << v1elem << " ";
     }
     cout << endl;
     
     cout << "v2: ";
     for(auto &v2elem: v2)
     {
         cout << v2elem << " ";
     }
     cout << endl;
     
     std::vector<int> v_intersection;
     
     cout << "v1 and v2 intersection:" << endl;
     std::set_intersection(v1.begin(), v1.end(),
                           v2.begin(), v2.end(),
                           std::back_inserter(v_intersection), vecCmp);
     for (int n : v_intersection)
         std::cout << n << ' ';
     
     std::vector<int> v_difference;
     
     // 在v1但不在v2中
     set_difference(v1.begin(), v1.end(), v_intersection.begin(), v_intersection.end(), inserter(v_difference, v_difference.begin()), vecCmp);
     
     cout << endl << "in v1 but not in v2:" << endl;
     for (int n : v_difference)
         cout << n << " ";
     cout << endl;

    printf("hello world!\n");
    return 0;
}