![]() |
VOOZH | about |
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} ]
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.
deque<set<type>> myDeque
The below example demonstrates how we can create a deque of sets in C++ STL.
myDeque: 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.