fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. int main() {
  6. std::vector<int> a{6, 10, 14, 20};
  7. std::vector<int> b{4, 8, 16, 20};
  8.  
  9. auto a_size = a.size();
  10.  
  11. a.insert(a.end(), b.begin(), b.end());
  12.  
  13. // merge point is where `a` and `b` meet: at the end of original `a`.
  14. std::inplace_merge(a.begin(), a.begin() + a_size, a.end());
  15.  
  16. auto last = std::unique(a.begin(), a.end());
  17. a.erase(last, a.end());
  18.  
  19. for(auto e: a) {
  20. std::cout << e << ' ';
  21. }
  22. std::cout << '\n';
  23. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
4 6 8 10 14 16 20