How to Create a Deque of Sets in C++? Last Updated : 27 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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, 5, 7} ]Creating a Deque of Sets in C++To create a std::deque of std::set in C++, we can simply pass the type of the deque container to be of type std::set as a template parameter while declaration. Syntax to Declare Deque of Setdeque<set<type>> myDequeC++ Program to Create a Deque of Sets The below example demonstrates how we can create a deque of sets in C++ STL. C++ // C++ Program to illustrate how to create a deque of set #include <deque> #include <iostream> #include <set> using namespace std; int main() { // Declaring a deque of sets deque<set<int> > myDeque; // Creating some sets set<int> set1 = { 1, 2, 3 }; set<int> set2 = { 4, 5, 6 }; set<int> set3 = { 7, 8, 9 }; // Pushing sets into the deque myDeque.push_back(set1); myDeque.push_back(set2); myDeque.push_back(set3); // Checking if the deque is empty cout << "myDeque: " << endl; int i = 1; for (auto& ele : myDeque) { cout << "Set" << i++ << ": "; for (auto i : ele) { cout << i << " "; } cout << endl; } return 0; } OutputmyDeque: Set1: 1 2 3 Set2: 4 5 6 Set3: 7 8 9 Time complexity: O(N*M), where N is the number of sets.Auxiliary Space: O(N*M), where M is the average size of the set. Comment More infoAdvertise with us Next Article How to Create a Deque of Sets in C++? P pantharshx9d9 Follow Improve Article Tags : C++ Programs C++ cpp-set cpp-deque CPP Examples +1 More Practice Tags : CPP Similar Reads 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 Set of Sets in C++? In C++, sets are STL containers that store unique elements of the same type in a sorted manner. Sets of sets, also known as nested sets, are collections in which each element of the outer set contains another set as its element. In this article, we will learn how to create a set of sets in C++. Set 2 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 a Stack of Set in C++? In C++ STL, Stacks are a type of container adaptor with LIFO(Last In First Out) type of working, where a new element is added at one end (top) and an element is removed from that end only. Sets are a type of associative container in which each element is unique and in some sorted order. In this arti 2 min read Like