Is there a way for adding multiple n elements to end of vector in O(1) complexity for C++17

411 Views Asked by At

I have try to develop an algorithm and in some times i should add multiple elements of a vector to another vector's end. Is there a way to proceed this in a constant time?

Also, is there a way for another data structures(such as arrays and iterators) to do that. I am not be restricted to use the vector.

//O(n) complexity

void add_to_vec( const std::vector<int>& src, std::vector<int & dest, int start, int n )
{
for( int i = 0; i < n; i++ ) {
dest.push_back( src[start + i] );
}
}
0

There are 0 best solutions below