![]() |
In C++, vectors are dynamic containers that can modify their size on insertion or deletion of elements during the runtime. It stores a collection of data in the contiguous memory location. In, this article we will learn how to merge two vectors in C++. Example: Input: myVector1={10, 30, 40} myVector2 ={20, 50, 60} Output: myVector3 = {10,20,30,40,50,60} Concatenate Two Vectors in C++We can simply merge two vectors using the std::merge() function provided by the Standard Template Library (STL) of C++. The function merges two vectors into a single one in sorted order. We have to pass the iterator to the beginning and the end of the vector containers. C++ Program to Merge Two VectorsC++
Output
Vector 1:10 30 40 Vector 2:20 50 60 Merged Vector:10 20 30 40 50 60 Time Complexity: O(N+M), where N and M are the lengths of both the vectors |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |