当前位置: 首页 > wzjs >正文

黄河道网站建设公司网站推广投放

黄河道网站建设公司,网站推广投放,线上推广引流平台,行业门户型网站std::set_intersection 用于计算两个已排序范围的交集。它将交集的结果写入到指定的输出迭代器中。 std::set_union 用于计算两个已排序范围的并集。它将并集的结果写入到指定的输出迭代器中。 std::set_difference 用于计算两个已排序范围的差集。它将差集的结果写入到指…

`std::set_intersection`  用于计算两个已排序范围的交集。它将交集的结果写入到指定的输出迭代器中。

`std::set_union`  用于计算两个已排序范围的并集。它将并集的结果写入到指定的输出迭代器中。

`std::set_difference`  用于计算两个已排序范围的差集。它将差集的结果写入到指定的输出迭代器中。差集是指在第一个范围中存在但在第二个范围中不存在的元素。

`std::set_symmetric_difference`  用于计算两个已排序范围的对称差集。对称差集是指在两个范围中存在但不在两个范围的交集中存在的元素。它将对称差集的结果写入到指定的输出迭代器中。

即:并集减差集:set_union - set_intersection

这几个函数默认使用 < 运算符,除非自定义比较函数。

std::set_intersection

用于计算两个已排序范围的交集。它将交集的结果写入到指定的输出迭代器中。

Defined in header <algorithm>

template< class InputIt1, class InputIt2, class OutputIt >

OutputIt set_intersection( InputIt1 first1, InputIt1 last1,
                           InputIt2 first2, InputIt2 last2,

                           OutputIt d_first );
(1)(constexpr since C++20)
template< class ExecutionPolicy,

          class ForwardIt1, class ForwardIt2, class ForwardIt3 >
ForwardIt3 set_intersection( ExecutionPolicy&& policy,
                             ForwardIt1 first1, ForwardIt1 last1,
                             ForwardIt2 first2, ForwardIt2 last2,

                             ForwardIt3 d_first );
(2)(since C++17)
template< class InputIt1, class InputIt2,

          class OutputIt, class Compare >
OutputIt set_intersection( InputIt1 first1, InputIt1 last1,
                           InputIt2 first2, InputIt2 last2,

                           OutputIt d_first, Compare comp );
(3)(constexpr since C++20)
template< class ExecutionPolicy,

          class ForwardIt1, class ForwardIt2,
          class ForwardIt3, class Compare >
ForwardIt3 set_intersection( ExecutionPolicy&& policy,
                             ForwardIt1 first1, ForwardIt1 last1,
                             ForwardIt2 first2, ForwardIt2 last2,

                             ForwardIt3 d_first, Compare comp );
(4)(since C++17)

Constructs a sorted range beginning at d_first consisting of elements that are found in both sorted ranges [first1last1) and [first2last2).

If [first1last1) contains m elements that are equivalent to each other and [first2last2) contains n elements that are equivalent to them, the first std::min(m, n) elements will be copied from [first1last1) to the output range, preserving order.

1) If [first1last1) or [first2last2) is not sorted with respect to operator<(until C++20)std::less{}(since C++20), the behavior is undefined.

3) If [first1last1) or [first2last2) is not sorted with respect to comp, the behavior is undefined.

2,4) Same as (1,3), but executed according to policy.

If the output range overlaps with [first1last1) or [first2last2), the behavior is undefined.

### 参数
- `first1`, `last1`: 第一个已排序范围的起始和结束迭代器。
- `first2`, `last2`: 第二个已排序范围的起始和结束迭代器。
- `d_first`: 输出范围的起始迭代器。
- `comp`: 二元谓词,用于比较元素。

### 返回值
返回一个迭代器,指向输出范围的末尾,即最后一个写入元素之后的位置。

### 示例
以下是一个简单的例子,演示如何使用 `std::set_intersection`:

#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>int main()
{std::vector<int> v1{7, 2, 3, 4, 5, 6, 7, 8};std::vector<int> v2{5, 7, 9, 7};std::sort(v1.begin(), v1.end());std::sort(v2.begin(), v2.end());std::vector<int> v_intersection;std::set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(),std::back_inserter(v_intersection));for (int n : v_intersection)std::cout << n << ' ';std::cout << '\n';
}

Output:

5 7 7

### 自定义比较函数

#include <iostream>
#include <vector>
#include <algorithm>bool compare(int a, int b) {return a < b;
}int main() {std::vector<int> vec1 = {1, 2, 3, 4, 5};std::vector<int> vec2 = {3, 4, 5, 6, 7};std::vector<int> result;std::set_intersection(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), std::back_inserter(result), compare);std::cout << "Intersection of vec1 and vec2: ";for (int n : result) {std::cout << n << " ";}std::cout << std::endl;return 0;
}

在这个例子中,`std::set_intersection` 使用 `compare` 函数来比较元素。

std::set_union

用于计算两个已排序范围的并集。它将并集的结果写入到指定的输出迭代器中。

### 语法

Defined in header <algorithm>

template< class InputIt1, class InputIt2, class OutputIt >

OutputIt set_union( InputIt1 first1, InputIt1 last1,
                    InputIt2 first2, InputIt2 last2,

                    OutputIt d_first );
(1)(constexpr since C++20)
template< class ExecutionPolicy,

          class ForwardIt1, class ForwardIt2, class ForwardIt3 >
ForwardIt3 set_union( ExecutionPolicy&& policy,
                      ForwardIt1 first1, ForwardIt1 last1,
                      ForwardIt2 first2, ForwardIt2 last2,

                      ForwardIt3 d_first );
(2)(since C++17)
template< class InputIt1, class InputIt2,

          class OutputIt, class Compare >
OutputIt set_union( InputIt1 first1, InputIt1 last1,
                    InputIt2 first2, InputIt2 last2,

                    OutputIt d_first, Compare comp );
(3)(constexpr since C++20)
template< class ExecutionPolicy,

          class ForwardIt1, class ForwardIt2,
          class ForwardIt3, class Compare >
ForwardIt3 set_union( ExecutionPolicy&& policy,
                      ForwardIt1 first1, ForwardIt1 last1,
                      ForwardIt2 first2, ForwardIt2 last2,

                      ForwardIt3 d_first, Compare comp );
(4)(since C++17)

Constructs a sorted union beginning at d_first consisting of the set of elements present in one or both sorted ranges [first1last1) and [first2last2).

If [first1last1) contains m elements that are equivalent to each other and [first2last2) contains n elements that are equivalent to them, then all m elements will be copied from [first1last1) to the output range, preserving order, and then the final std::max(n - m, 0) elements will be copied from [first2last2) to the output range, also preserving order.

1) If [first1last1) or [first2last2) is not sorted with respect to operator<(until C++20)std::less{}(since C++20), the behavior is undefined.

3) If [first1last1) or [first2last2) is not sorted with respect to comp, the behavior is undefined.

2,4) Same as (1,3), but executed according to policy.

 These overloads participate in overload resolution only if all following conditions are satisfied:

If the output range overlaps with [first1last1) or [first2last2), the behavior is undefined.

### 参数
- `first1`, `last1`: 第一个已排序范围的起始和结束迭代器。
- `first2`, `last2`: 第二个已排序范围的起始和结束迭代器。
- `d_first`: 输出范围的起始迭代器。
- `comp`: 二元谓词,用于比较元素。

### 返回值
返回一个迭代器,指向输出范围的末尾,即最后一个写入元素之后的位置。

### 示例
以下是一个简单的例子,演示如何使用 `std::set_union`:

#include <iostream>
#include <vector>
#include <algorithm>int main() {std::vector<int> vec1 = {1, 2, 3, 4, 5};std::vector<int> vec2 = {3, 4, 5, 6, 7};std::vector<int> result;std::set_union(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), std::back_inserter(result));std::cout << "Union of vec1 and vec2: ";for (int n : result) {std::cout << n << " ";}std::cout << std::endl;return 0;
}

output:

Union of vec1 and vec2: 1 2 3 4 5 6 7 

### 自定义比较函数

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>struct MyStruct {int key;int value;
};// 自定义比较函数,比较 MyStruct 的 value 成员的绝对值
bool compare(const MyStruct& a, const MyStruct& b) {return std::abs(a.value) < std::abs(b.value);
}int main() {std::vector<MyStruct> vec1 = {{1, 10}, {2, -20}, {3, 30}, {4, -40}, {5, 50}};std::vector<MyStruct> vec2 = {{3, -300}, {4, 400}, {5, -500}, {6, 600}, {7, -700}};std::vector<MyStruct> result;std::set_union(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), std::back_inserter(result), compare);std::cout << "Union of vec1 and vec2: ";for (const auto& elem : result) {std::cout << "{" << elem.key << ", " << elem.value << "} ";}std::cout << std::endl;return 0;
}

在这个例子中,`std::set_union` 使用 `compare` 函数来比较元素。

std::set_difference 

用于计算两个已排序范围的差集。它将差集的结果写入到指定的输出迭代器中。差集是指在第一个范围中存在但在第二个范围中不存在的元素。

### 语法

Defined in header <algorithm>

template< class InputIt1, class InputIt2, class OutputIt >

OutputIt set_difference( InputIt1 first1, InputIt1 last1,
                         InputIt2 first2, InputIt2 last2,

                         OutputIt d_first );
(1)(constexpr since C++20)
template< class ExecutionPolicy,

          class ForwardIt1, class ForwardIt2, class ForwardIt3 >
ForwardIt3 set_difference( ExecutionPolicy&& policy,
                           ForwardIt1 first1, ForwardIt1 last1,
                           ForwardIt2 first2, ForwardIt2 last2,

                           ForwardIt3 d_first );
(2)(since C++17)
template< class InputIt1, class InputIt2,

          class OutputIt, class Compare >
OutputIt set_difference( InputIt1 first1, InputIt1 last1,
                         InputIt2 first2, InputIt2 last2,

                         OutputIt d_first, Compare comp );
(3)(constexpr since C++20)
template< class ExecutionPolicy,

          class ForwardIt1, class ForwardIt2,
          class ForwardIt3, class Compare >
ForwardIt3 set_difference( ExecutionPolicy&& policy,
                           ForwardIt1 first1, ForwardIt1 last1,
                           ForwardIt2 first2, ForwardIt2 last2,

                           ForwardIt3 d_first, Compare comp );
(4)(since C++17)

Copies the elements from the sorted range [first1last1) which are not found in the sorted range [first2last2) to the range beginning at d_first. The output range is also sorted.

If [first1last1) contains m elements that are equivalent to each other and [first2last2) contains n elements that are equivalent to them, the final std::max(m - n, 0) elements will be copied from [first1last1) to the output range, preserving order.

1) If [first1last1) or [first2last2) is not sorted with respect to operator<(until C++20)std::less{}(since C++20), the behavior is undefined.

3) If [first1last1) or [first2last2) is not sorted with respect to comp, the behavior is undefined.

2,4) Same as (1,3), but executed according to policy.

 If the output range overlaps with [first1last1) or [first2last2), the behavior is undefined.

### 参数
- `first1`, `last1`: 第一个已排序范围的起始和结束迭代器。
- `first2`, `last2`: 第二个已排序范围的起始和结束迭代器。
- `d_first`: 输出范围的起始迭代器。
- `comp`: 二元谓词,用于比较元素。

### 返回值
返回一个迭代器,指向输出范围的末尾,即最后一个写入元素之后的位置。

### 示例
以下是一个简单的例子,演示如何使用 `std::set_difference`:

//在vec1中不在vec2中的元素

#include <iostream>
#include <vector>
#include <algorithm>int main() {std::vector<int> vec1 = {1, 3, 2, 4, 5};std::vector<int> vec2 = {3, 5, 4, 6, 7};std::vector<int> result;std::sort(vec1.begin(), vec1.end());std::sort(vec2.begin(), vec2.end());std::set_difference(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), std::back_inserter(result));std::cout << "Difference of vec1 and vec2: ";for (int n : result) {std::cout << n << " ";}std::cout << std::endl;return 0;
}

输出:

Difference of vec1 and vec2: 1 2 

### 自定义比较函数

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>struct MyStruct {int key;int value;
};// 自定义比较函数,比较 MyStruct 的 value 成员的绝对值
bool compare(const MyStruct& a, const MyStruct& b) {return std::abs(a.value) < std::abs(b.value);
}int main() {std::vector<MyStruct> vec1 = {{1, 10}, {2, -20}, {3, 30}, {4, -40}, {5, 50}, {9, -90}};std::vector<MyStruct> vec2 = {{3, -300}, {4, 400}, {5, -500}, {6, 600}, {7, -700}, {10, 1000}};std::vector<MyStruct> result;std::set_difference(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), std::back_inserter(result), compare);std::cout << "Difference of vec1 and vec2: ";for (const auto& elem : result) {std::cout << "{" << elem.key << ", " << elem.value << "} ";}std::cout << std::endl;return 0;
}

在这个例子中,`std::set_difference` 使用 `compare` 函数来比较元素。

std::set_symmetric_difference 

用于计算两个已排序范围的对称差集。对称差集是指在两个范围中存在但不在两个范围的交集中存在的元素。它将对称差集的结果写入到指定的输出迭代器中。

即:并集减差集

### 语法

Defined in header <algorithm>

template< class InputIt1, class InputIt2, class OutputIt >

OutputIt set_symmetric_difference
    ( InputIt1 first1, InputIt1 last1,
      InputIt2 first2, InputIt2 last2,

      OutputIt d_first );
(1)(constexpr since C++20)
template< class ExecutionPolicy,

          class ForwardIt1, class ForwardIt2, class ForwardIt3 >
ForwardIt3 set_symmetric_difference
    ( ExecutionPolicy&& policy,
      ForwardIt1 first1, ForwardIt1 last1,
      ForwardIt2 first2, ForwardIt2 last2,

      ForwardIt3 d_first );
(2)(since C++17)
template< class InputIt1, class InputIt2,

          class OutputIt, class Compare >
OutputIt set_symmetric_difference
    ( InputIt1 first1, InputIt1 last1,
      InputIt2 first2, InputIt2 last2,

      OutputIt d_first, Compare comp );
(3)(constexpr since C++20)
template< class ExecutionPolicy,

          class ForwardIt1, class ForwardIt2,
          class ForwardIt3, class Compare >
ForwardIt3 set_symmetric_difference
    ( ExecutionPolicy&& policy,
      ForwardIt1 first1, ForwardIt1 last1,
      ForwardIt2 first2, ForwardIt2 last2,

      ForwardIt3 d_first, Compare comp );

### 参数
- `first1`, `last1`: 第一个已排序范围的起始和结束迭代器。
- `first2`, `last2`: 第二个已排序范围的起始和结束迭代器。
- `d_first`: 输出范围的起始迭代器。
- `comp`: 二元谓词,用于比较元素。

### 返回值
返回一个迭代器,指向输出范围的末尾,即最后一个写入元素之后的位置。

### 示例

#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>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());std::sort(v2.begin(), v2.end());std::vector<int> v_symDifference;std::set_symmetric_difference(v1.begin(), v1.end(), v2.begin(), v2.end(),std::back_inserter(v_symDifference));for (int n : v_symDifference)std::cout << n << ' ';std::cout << '\n';
}

Output:

1 2 3 4 6 8 9 10

### 自定义比较函数
 

#include <iostream>
#include <vector>
#include <algorithm>struct MyStruct {int key;int value;
};bool compare(const MyStruct& a, const MyStruct& b) {return a.key < b.key;
}int main() {std::vector<MyStruct> vec1 = {{1, 10}, {2, 20}, {3, 30}, {4, 40}, {5, 50}};std::vector<MyStruct> vec2 = {{3, 300}, {4, 400}, {5, 500}, {6, 600}, {7, 700}};std::vector<MyStruct> result;std::set_symmetric_difference(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), std::back_inserter(result), compare);std::cout << "Symmetric difference of vec1 and vec2: ";for (const auto& elem : result) {std::cout << "{" << elem.key << ", " << elem.value << "} ";}std::cout << std::endl;return 0;
}

output:

Symmetric difference of vec1 and vec2: {1, 10} {2, 20} {6, 600} {7, 700} 

在这个例子中,`std::set_symmetric_difference` 使用 `compare` 函数来比较元素。

http://www.dtcms.com/wzjs/126797.html

相关文章:

  • 在线制作logo网站百度视频推广
  • 网站留言板怎么做phpsql百度一下全知道
  • linux 如何做网站网络口碑营销案例分析
  • 网站建设项目延期验收申请八种营销模式
  • 郑州营销型网站建设公司百度网盘下载电脑版官方下载
  • 泉州市知名网站建设公司南昌seo招聘信息
  • 网站开发排名网站搭建需要什么技术
  • 云羽网络做网站怎么样seo网络营销推广排名
  • 网站开发报价表seo公司排名教程
  • 包装纸箱怎么做网站外贸seo优化
  • 柳市网站建设哪家好搜索引擎seo关键词优化效果
  • 网站建设中 英语百度广告推广费用一年多少钱
  • 网站建设的途径简单的网页设计作品
  • 网站用户量搜索引擎优化的七个步骤
  • 做网站建设小程序企业建站都有什么网站
  • 网站建设流程与构架成都网站关键词推广优化
  • 创新模式_提高质量_建设一流的数学人才培养基地 教学成果奖申报网站王通seo
  • 手机版的网站用什么开发营销推广方式有哪些
  • 怎么下载自己做的网站今日热点新闻视频
  • 中山古镇做网站站长工具whois查询
  • 赌球网站如何做代理seo网站编辑优化招聘
  • 西安网站手机网站建设关键词排名网络推广
  • 百度云网站建设自己做一个网站要多少钱
  • 襄阳地区网站做的好的百度贴吧官网入口
  • 衢州手机网站建设黄冈seo
  • wordpress 修改主题页面陕西seo顾问服务
  • 做静态网站需要什么黑帽seo教程
  • 建设工程施工许可证办理网站整合营销传播名词解释
  • 武汉精品网站建设各大网站收录查询
  • 网站建设可行性及需求分析百度优化师