Code:
#include <functional>
#include <iostream>
#include <iterator>
#include <vector>
int main ()
{
typedef std::vector<int, std::allocator<int> > Vector;
const Vector::value_type d1[] = { 1, 2, 3, 4};
const Vector::value_type d2[] = { 11, 13, 15, 17,
12, 14, 16, 18};
Vector v1 (d1 + 0, d1 + sizeof d1 / sizeof *d1);
Vector v2 (d1 + 0, d1 + sizeof d1 / sizeof *d1);
Vector v3 (d2 + 0, d2 + sizeof d2 / sizeof *d2);
Vector v4 (v3);
Vector v5 (v3);
Vector v6 (v3);
Vector v7;
std::merge (v1.begin (), v1.end (),
v2.begin (), v2.end (), v3.begin ());
std::merge (v1.begin (), v1.end (),
v2.begin (), v2.end (), v4.begin (),
std::less<int>());
Vector::iterator mid = v5.begin ();
std::advance (mid, 4);
std::inplace_merge (v5.begin (), mid, v5.end ());
mid = v6.begin ();
std::advance (mid, 4);
std::inplace_merge (v6.begin (), mid, v6.end (),
std::less<int>());
std::merge (v1.begin (), v1.end (),
v2.begin (), v2.end (),
std::back_inserter (v7));
std::ostream_iterator<int, char, std::char_traits<char> >
out (std::cout," ");
std::copy (v1.begin (), v1.end (), out);
std::cout << std::endl;
std::copy (v2.begin(), v2.end (), out);
std::cout << std::endl;
std::copy (v3.begin (), v3.end (), out);
std::cout << std::endl;
std::copy (v4.begin (), v4.end (), out);
std::cout << std::endl;
std::copy (v5.begin (), v5.end (), out);
std::cout << std::endl;
std::copy (v6.begin (),v6.end (), out);
std::cout << std::endl;
std::copy (v7.begin (), v7.end (), out);
std::cout << std::endl;
std::merge (v1.begin (), v1.end (),
v2.begin (), v2.end (), out);
return 0;
}
Program Output:
Bookmarks