To
do: Using the C++ STL set_union() to unite all of the elements that belong to at
least one of two sorted source ranges into a single, sorted destination range, where
the ordering criterion may be specified by a binary predicate

To
show: How to use the C++ algorithm, set_union() to unite all of the elements that
belong to at least one of two sorted source ranges into a single, sorted destination
range, where the ordering criterion may be specified by a binary predicate in C++
programming

// C++ STL algorithm set_union()

#include<vector>

#include<algorithm>

// for greater<int>()

#include<functional>

#include<iostream>

usingnamespace std;

// return whether modulus of elem1 is less than modulus of elem2

bool
mod_lesser(int elem1, int
elem2)

{

if(elem1 < 0)

elem1
= - elem1;

if(elem2 < 0)

elem2
= - elem2;

return (elem1 < elem2);

}

int main(void)

{

// vector containers

vector<int>
vec1a, vec1b, vec1(15);

// vector iterators

vector<int>::iterator
Iter1a, Iter1b, Iter1, Result1;

// constructing vectors vec1a & vec1b with default
less than ordering

int
i, j;

for(i = -3; i <= 3;
i++)

vec1a.push_back(i);

for(j =-7; j <= 7;
j++)

vec1b.push_back(j);

cout<<"Original
vector vec1a with range sorted by the binary predicate less than is: ";

for(Iter1a = vec1a.begin();
Iter1a != vec1a.end(); Iter1a++)

cout<<*Iter1a<<"
";

cout<<endl;

cout<<"\nOriginal
vector vec1b with range sorted by the binary predicate less than is: ";