How to Create Deque of Unordered_Set in C++? Last Updated : 27 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In C++, a deque (double-ended queue) is a container that allows insertion and removal of elements from both ends whereas an unordered set is a container that stores unique elements in no particular order. In this article, we will learn how to create a deque of unordered sets in C++ STL. Example:Input: myUSet1 = {1, 2, 3} myUSet2 = {4, 5, 6} Output: Deque Elements: uSet1: 3 1 2 uSet2: 6 4 5 Creating Deque of Unordered_Set in C++To create a std::deque of std::unordered_set, we can use the std::deque template class that takes the type of the elements as a template parameter. We can pass the type as an unordered_set of a given type. Syntax to Declare Deque of Unordered Setdeque<unordered_set<Type>> myDeque;C++ Program to Create Deque of Unordered_SetThe below program demonstrates how we can create a deque of unordered_sets in C++. C++ // C++ program to illustrate how to create a deque of // unordered sets #include <deque> #include <iostream> #include <unordered_set> using namespace std; int main() { // Declaring a deque of unordered sets deque<unordered_set<int> > myDeque; // Creating some unordered sets unordered_set<int> set1 = { 1, 2, 3 }; unordered_set<int> set2 = { 4, 5, 6 }; // Pushing unordered sets into the deque myDeque.push_back(set1); myDeque.push_back(set2); // Checking if the deque is empty cout << "Deque Elements: " << endl; int count = 1; for (auto& ele : myDeque) { cout << "uSet" << count << ": "; for (auto i : ele) { cout << i << " "; } count++; cout << endl; } return 0; } OutputDeque Elements: uSet1: 3 1 2 uSet2: 6 4 5 Time Complexity: O(N*M), where N is the number of sets and M is the average size of each set.Auxilliary Space: O(N*M) Comment More infoAdvertise with us Next Article How to Create Deque of Unordered_Set in C++? G gauravgandal Follow Improve Article Tags : C++ Programs C++ STL cpp-unordered_set cpp-deque CPP Examples +2 More Practice Tags : CPPSTL Similar Reads How to Create Stack of Unordered Set in C++? In C++, a stack is a container adapter that provides a Last-In-First-Out (LIFO) type of data structure, and an unordered set is a container that stores unique elements in no particular order. In this article, we will learn how to create a stack of unordered sets in C++. Creating a Stack of Unordered 2 min read How to Create a Deque of Sets in C++? In C++, a container called deque is a queue like container but allows for fast insertions and deletions at both ends. In this article, we will learn how to create a deque of sets in C++. Example: Input: mySet1 = {1, 4, 8, 9, 11} mySet2 = {1, 2, 3, 5, 7} Output: myDeque: [ {1, 4, 8, 9, 11}, {1, 2, 3, 2 min read How to Create a Stack of Deque in C++? In C++, the stack is a container in which new elements are added from one end (top) and removed from that end only whereas a deque (double-ended queue) are sequence container with the feature of expansion and contraction on both ends. In this article, we will learn how to create a stack of deque in 2 min read How to Create a Deque of Vectors in C++? In C++, deques are sequence containers similar to queues but unlike queues, deques allow the insertion and deletion of elements from both ends efficiently. Vectors are dynamic arrays that can resize themselves during the runtime. In this article, we will learn how to create a deque of vectors in C++ 2 min read How to Create a Stack of Unordered_Multiset in C++? In C++, the stack is a container in which new elements are added from one end (top) and removed from that end only. In this article, we will learn how to create a stack of unordered_multiset in C++. Example: Input: mySet1 = { âappleâ, âbananaâ, âappleâ } mySet2 = { âorangeâ, âmangoâ, âorangeâ } Outp 2 min read Like