标签:col 比较 集合 function main fir 自定义 style bsp
//版本一:用operator <比较元素 template <class InputerIterator1,class InputerIterator2> bool includes(InputerIterator1 first1,InputerIterator1 last1,InputerIterator2 first2,InputerIterator2 last2); //版本二:用自定义的function object比较元素 template <class InputerIterator1,class InputerIterator2,class StrictWeakOrdering> bool includes(InputerIterator1 first1,InputerIterator1 last1,InputerIterator2 first2,InputerIterator2 last2,StrictWeakOrdering cmp);
测试已排序的[first2,last2)是否为[first1,last1)的子集,每个集合中的元素不必独一无二,如果某个元素在[first1,last1)出现m次,在[first2,last2)出现n次,如果m<n,则返回false
//版本一:用operator <比较元素 template <class InputerIterator1,class InputerIterator2,class OutputIterator> OutputIterator set_union(InputerIterator1 first1,InputerIterator1 last1, InputerIterator2 first2,InputerIterator2 last2,OutputIterator rseult); //版本二:用自定义的function object比较元素 template <class InputerIterator1,class InputerIterator2,class OutputIterator,class StrictWeakOrdering> OutputIterator set_union(InputerIterator1 first1,InputerIterator1 last1, InputerIterator2 first2,InputerIterator2 last2, OutputIterator result,StrictWeakOrdering cmp);
构造已排序的[first2,last2)和[first1,last1)的联集,每个集合中的元素不必独一无二
//版本一:用operator <比较元素 template <class InputerIterator1,class InputerIterator2,class OutputIterator> OutputIterator set_intersection(InputerIterator1 first1,InputerIterator1 last1, InputerIterator2 first2,InputerIterator2 last2,OutputIterator rseult); //版本二:用自定义的function object比较元素 template <class InputerIterator1,class InputerIterator2,class OutputIterator,class StrictWeakOrdering> OutputIterator set_intersection(InputerIterator1 first1,InputerIterator1 last1, InputerIterator2 first2,InputerIterator2 last2, OutputIterator result,StrictWeakOrdering cmp);
构造两个集合的交集
如果某个元素在[first1,last1)出现n次,在[first2,last2)出现m次,在result中出现的次数为min(n,m),所有元素赋值于[first1,last1),其他的与set_union相同
//版本一:用operator <比较元素 template <class InputerIterator1,class InputerIterator2,class OutputIterator> OutputIterator set_difference(InputerIterator1 first1,InputerIterator1 last1, InputerIterator2 first2,InputerIterator2 last2,OutputIterator rseult); //版本二:用自定义的function object比较元素 template <class InputerIterator1,class InputerIterator2,class OutputIterator,class StrictWeakOrdering> OutputIterator set_difference(InputerIterator1 first1,InputerIterator1 last1, InputerIterator2 first2,InputerIterator2 last2, OutputIterator result,StrictWeakOrdering cmp);
构造两个集合的差集,result中的元素出现于第一个range但不出现于第二个range
某个元素在[first1,last1)中拥有n个彼此等价的元素,在[first2,last2)中拥有m个彼此等价的元素,result中含有max(n-m)个彼此等价的元素,所有元素都复制于[first1,last1)
//版本一:用operator <比较元素 template <class InputerIterator1,class InputerIterator2,class OutputIterator> OutputIterator set_symmetric_difference(InputerIterator1 first1,InputerIterator1 last1, InputerIterator2 first2,InputerIterator2 last2,OutputIterator rseult); //版本二:用自定义的function object比较元素 template <class InputerIterator1,class InputerIterator2,class OutputIterator,class StrictWeakOrdering> OutputIterator set_symmetric_difference(InputerIterator1 first1,InputerIterator1 last1, InputerIterator2 first2,InputerIterator2 last2, OutputIterator result,StrictWeakOrdering cmp);
构造出两个集合之对称差,结果集包含出现于第一个range的元素但不出现于第二个range的元素以及出现于第二个range的元素但不出现于第一个range的元素
某个元素在[first1,last1)中拥有n个彼此等价的元素,在[first2,last2)中拥有m个彼此等价的元素,result中含有|n-m|个彼此等价的元素,若n>m,则result元素中最后n-m个将由[first1,last1)复制来,若n<m,则result元素中最后m-n个将由[first2,last2)复制来
#include <iostream> #include <vector> #include <iterator> #include <algorithm> using namespace std; int main() { vector<int> v{1,2,3,4,5,6,6,6}; vector<int> v1{1,5,6}; vector<int> v2{1,9,10,11}; cout<<includes(v.begin(),v.end(),v1.begin(),v1.end())<<endl; set_union(v2.begin(),v2.end(),v1.begin(),v1.end(),ostream_iterator<int>(cout," ")); cout<<endl; set_intersection(v.begin(),v.end(),v1.begin(),v1.end(),ostream_iterator<int>(cout," ")); set_difference(v1.begin(),v1.end(),v.begin(),v.end(),ostream_iterator<int>(cout," ")); cout<<endl; set_symmetric_difference(v.begin(),v.end(),v2.begin(),v2.end(),ostream_iterator<int>(cout," ")); cout<<endl; return 0; }
includes,set_union,set_intersection,set_difference
标签:col 比较 集合 function main fir 自定义 style bsp
原文地址:https://www.cnblogs.com/tianzeng/p/10392445.html