Generic merge algorithms: Merge the two sorted halves of vector3 in place to obtain a sorted vector3 : inplace_merge « STL Algorithms Merge « C++






Generic merge algorithms: Merge the two sorted halves of vector3 in place to obtain a sorted vector3

 
 
#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
  vector<int> vector1(5);
  vector<int> vector2(5);
  vector<int> vector3(10);

  for (int i = 0; i < 5; ++i)
    vector1[i] = 2 * i;

  for (int i = 0; i < 5; ++i)
    vector2[i] = 1 + 2 * i;


  merge(vector1.begin(), vector1.end(), vector2.begin(), vector2.end(), vector3.begin());

  
  inplace_merge(vector3.begin(), vector3.begin() + 5,vector3.end());

  for (int i = 0; i < 10; ++i)
    cout << vector3[i];

  return 0;
}

/* 
0123456789
 */        
  








Related examples in the same category

1.std::inplace_merge
2.inplace_merge a list