-1

i think we can connect end of VEC1 to connect with begin of VEC2 but HOW??

EXAMPLE

VEC1 : (VEC1.begin()) -> 'H' -> 'A' -> 'P' -> 'P' ->'Y' -> (VEC1.end)

VEC2 : (VEC2.begin()) -> '1' -> '2' -> '3' -> '4' -> (VEC2.end)

.

// VEC1.insert() : but it's mean we .push_back() everytime O(n)

VEC1 = HAPPY1234

VEC2 = 1234

.

.

so it's have anyway to do like O(2)

VEC1 : (VEC1.begin()) -> 'H' -> 'A' -> 'P' -> 'P' ->'Y' -> (VEC1.end)

. . . . . . . . . . . . . . . . . . . . . . ___________________| . . . . . . . | . . . .

. . . . . . . . . . . . . . . . . . . . . . | . . . . . . . . . . . . . _____________| . . . .

. . . . . . . . . . . . . . . . . . . . . . | . . . . . . . . . . . . . | . . . . . . . . . . . . . . . . .

VEC2 : (VEC2.begin()) -> '1' -> '2' -> '3' -> '4' -> (VEC2.end)

. . . . . . . . . . . . | . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | . . . . . . . .

. . . . . . . . . . . . __________________________________ . . . . . . .

.

.

VEC1 = HAPPY1234

VEC2 = NULL; (empty)

.

So please, Can you tell me how to do connect 2 vector by address or something ;

  • If that was supposed to be an ASCII diagram, it sort of came out all mangled. What do you mean by O(2)? – tadman Apr 19 '16 at 17:48
  • It's difficult to tell what you're asking based on the lack of formatting in your question. – TriskalJM Apr 19 '16 at 17:50
  • 1
    Dupe of: http://stackoverflow.com/questions/201718/concatenating-two-stdvectors using this answer: http://stackoverflow.com/a/21972296/4342498 – NathanOliver Apr 19 '16 at 17:51
  • @NathanOliver no. Because that would make sense. – Yakk - Adam Nevraumont Apr 19 '16 at 18:02
  • @Yakk I know it is not the answer the OP wants but AFAIK it is the only way to do what they want. – NathanOliver Apr 19 '16 at 18:04
  • @NathanOliver So, not a dupe. Now, the OP could write a random-access-container type-eraser, wrap the two vectors in it, then use a move-based concatinate on the random-access-container-type-eraser to be able to access them uniformly. It would be O(number of containers) not O(number of elements) as the OP wants, with access time of O(depth of concatinate tree) (in this case, O(1)). Not a good idea, and not `std::vector`s afterwards, but would do what the OP wanted. – Yakk - Adam Nevraumont Apr 19 '16 at 18:08

1 Answers1

0

I understand that you want to move the content of vec2 at the end of vec1, but without making any copy. You could use std::move:

#include <utility>

std::size_t size = a.size();
a.resize(size + b.size());
std::move(b.begin(), b.end(), a.begin() + size);
Luc
  • 164
  • 1
  • 10