1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <iostream>
#include <set>
using namespace std;
template <typename X> void addMissing( set<X> &T, set<X> N )
{
for ( X element : N ) T.insert( element ); // if there, do nothing; if not there then insert
}
//======================================================================
template <typename X> void printSet( string title, set<X> S )
{
cout << title << " ";
for ( X element : S ) cout << element << " ";
cout << endl;
}
//======================================================================
int main()
{
set<int> T{ 1, 3, 5, 7, 9 };
set<int> N{ 1, 2, 4, 6, 7, 8, 9 };
printSet( "Set T: ", T );
printSet( "Set N: ", N );
addMissing( T, N );
printSet( "Set T u N: ", T );
}
|