VOOZH about

URL: https://www.geeksforgeeks.org/cpp/deque-of-sets-in-cpp/

⇱ How to Create a Deque of Sets in C++? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Create a Deque of Sets in C++?

Last Updated : 23 Jul, 2025

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 Set

deque<set<type>> myDeque

C++ Program to Create a Deque of Sets

The below example demonstrates how we can create a deque of sets in C++ STL.


Output
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.



Comment