1

I have two vectors that I want to merge without sorting the elements:

A = [a d f h]
B = [b c e g]
C = [a d f h b c e g]  // I want this

std::merge and std::inplace_merge end up sorting the vectors. Is there any way of doing this other than manually reading the two vectors in succession and pushing the values into a new vector?

user1420
  • 143
  • 2
  • 11

1 Answers1

5
vector<T> C(A);
C.insert(C.end(), B.begin(), B.end());
for_stack
  • 21,012
  • 4
  • 35
  • 48