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 36 37
|
#include <iostream>
#include <algorithm>
#include <boost/range.hpp>
#include <boost/range/join.hpp>
#include <boost/range/algorithm.hpp>
void show(int* p1, int n1, int* p2, int n2)
{
std::cout << "Arrays contain: ";
for(int n=0; n<n1; ++n)
std::cout << p1[n] << ' ';
std::cout << ": ";
for(int n=0; n<n2; ++n)
std::cout << p2[n] << ' ';
std::cout << '\n';
}
const int a1[] = {1, 5, 35, 2, 7};
const int a2[] = {-1, 4, 8, 3};
int main()
{
int c = 5;
int* first = new int[c];
std::copy(a1, a1+c, first);
int d = 4;
int* second = new int[d];
std::copy(a2, a2+d, second);
show(first, c, second, d);
sort(join(boost::make_iterator_range(first, first+c),
boost::make_iterator_range(second, second+d)));
show(first, c, second, d);
delete[] first;
delete[] second;
}
|
Arrays contain: 1 5 35 2 7 : -1 4 8 3
Arrays contain: -1 1 2 3 4 : 5 7 8 35 |