How to Concatenate Two Deques in C++? Last Updated : 27 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In C++S, we have a sequence container called deque (an acronym for double-ended queue) that allows the insertions and deletions at both its beginning and its end. In this article, we will learn how to concatenate two deques in C++ STL. Example: Input: deque1 = {10, 20, 30}; deque2 = {40, 50, 60}; Output: Concatenated deque is : 10 20 30 40 50 60Merge Two Deques in C++ We can merge two deques using the std::deque::insert() function that inserts elements from the given range. We have to pass the iterator to the end of the first deque and the iterators to the beginning and the end of the second deque in the function. Syntax to Concatenate Two Deques in C++ deque1.insert(deque1.end(), deque2.begin(), deque2.end());Here, deque1 and deque2 are the names of the first deque and second deque respectively. C++ Program to Concatenate Two Deques The below example demonstrates how we can use the insert() function to concatenate two deques in C++ STL. C++ // C++ program to demonstrates how we can use the insert() // function to concatenate two deques #include <deque> #include <iostream> using namespace std; int main() { // Creating two deques deque<int> deque1 = { 10, 20, 30 }; deque<int> deque2 = { 40, 50, 60 }; // Concatenating the deques deque1.insert(deque1.end(), deque2.begin(), deque2.end()); // Printing the concatenated deque cout << "Concatenated deque is : "; for (int i : deque1) { cout << i << " "; } cout << endl; return 0; } OutputConcatenated deque is : 10 20 30 40 50 60 Time Complexity: O(M), here N is the number of elements in the second deque.Auxiliary Space: O(M) Comment More infoAdvertise with us Next Article How to Create a Deque of Maps in C++? D denzirop9v Follow Improve Article Tags : C++ Programs C++ STL cpp-deque CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Compare Two Deques in C++? In C++ the Standard Template Library (STL) provides a container called deque (short for double-ended queue) that allows fast insertions and deletions at both ends of the deque. In this article, we will learn how to compare two deques in C++. Example: Input: deque1 = {10,20,30}; deque2 = {10,20,30}; 2 min read How to Concatenate Two Sets in C++? In C++, sets are the data containers that store the unique elements in some specified order. Concatenating two sets means merging the elements of two sets into the first set. In this article, we will learn how to concatenate two sets in C++ STL. Example Input: mySet1 = {1, 2, 3, 4, 5, 8, 9} mySet2 = 2 min read How to Concatenate Two Arrays in C++? In C++, arrays store a fixed number of elements of the same type in contiguous memory locations. In this article, we will learn how to concatenate two arrays in C++. Example: Input: myArray1={10, 30, 40} myArray2 ={20, 50, 60}Output: Concatenated Array: 10 30 40 20 50 60 Concatenate Two Arrays in On 2 min read How to Concatenate Two Vectors in C++? Concatenation of two vectors refers to the process of adding the elements of one vector at the end of another vector. In this article, we will learn how to concatenate two vectors in C++.The simplest method to concatenate the two vectors is by using the vector insert() method. Letâs take a look at a 3 min read How to Create a Deque of Maps in C++? In C++, the Standard Template Library (STL) provides a container called deque that allows efficient insertion and deletion operations at both ends of the container. A map is an associative container that stores elements in key-value pairs.In this article, we will learn how to create a deque of maps 2 min read How to Create Deque of Multiset in C++? In C++, deques are containers that allow efficient insertion and deletion operations from both ends. Multisets are associative containers similar to sets but unlike sets, multisets allow duplicate insertions as well. In this article, we will learn how to create a deque of multiset in C++. Example In 2 min read Like