C++.


set_union()


template< class InputIterator1, class InputIterator2,

class OutputIterator >

OutputIterator

set_union(InputIterator1 first1, InputIterator1 last1,

InputIterator2 first2, InputIterator2 last2,

OutputIterator result );

template< class InputIterator1, class InputIterator2,

class OutputIterator, class Compare >

OutputIterator

set_union(InputIterator1 first1, InputIterator1 last1,

InputIterator2 first2, InputIterator2 last2,

OutputIterator result, Compare comp );

set_union()

, [first1,last1),   [first2,last2), . , {0,1,2,3} {0,2,4,6} {0,1,2,3,4,6}. , . result. , , ; comp.

#include <algorithm>

#include <set>

#include <string>

#include <iostream.h>

 

/* :

#1:

-

 

#2:

 

set_union():

-

 

set_intersection():

 

set_difference():

-

 

_symmetric_difference():

-

*/

int main()

{

string str1[] = { "", "", "", "-" };

string str2[] = { "", "", "" };

ostream_iterator< string > ofile( cout, " " );

set<string,less<string>,allocator> set1( str1, str1+4 );

set<string,less<string>,allocator> set2( str2, str2+3 );

 

cout << " #1:\n\t";

copy( set1.begin(), set1.end(), ofile ); cout << "\n\n";

cout << " #2:\n\t";

copy( set2.begin(), set2.end(), ofile ); cout << "\n\n";

 

set<string,less<string>,allocator> res;

set_union( set1.begin(), set1.end(),

set2.begin(), set2.end(),

inserter( res, res.begin() ));

 

cout << " set_union():\n\t";

copy( res.begin(), res.end(), ofile ); cout << "\n\n";

 

res.clear();

set_intersection( set1.begin(), set1.end(),

set2.begin(), set2.end(),

inserter( res, res.begin() ));

 

cout << " set_intersection():\n\t";

copy( res.begin(), res.end(), ofile ); cout << "\n\n";

 

res.clear();

set_difference( set1.begin(), set1.end(),

set2.begin(), set2.end(),

inserter( res, res.begin() ));

 

cout << " set_difference():\n\t";

copy( res.begin(), res.end(), ofile ); cout << "\n\n";

 

res.clear();

set_symmetric_difference( set1.begin(), set1.end(),

set2.begin(), set2.end(),

inserter( res, res.begin() ));

 

cout << " set_symmetric_difference():\n\t";

copy( res.begin(), res.end(), ofile ); cout << "\n\n";

}