How to Create a Set of Arrays in C++? Last Updated : 21 Feb, 2024 Comments Improve Suggest changes Like Article Like Report In C++, the set container represents a collection of unique, sorted elements, and an array is a collection of items stored at contiguous memory locations. In this article, we will learn about how to create a set of arrays in C++. Set of Arrays in C++A set of arrays refers to a collection of arrays where each array is unique within the set. In other words, no two arrays in the set are identical. We can create the set of arrays by specifying the type of the set container to be array. Syntaxset<array<ElementType, Size>> VariableName; C++ Program to Create a Set of Arrays C++ // C++ program to Create a Set of Arrays #include <array> #include <iostream> #include <set> using namespace std; // Driver Code int main() { // Declare a set containing arrays of 3 integers set<array<int, 3> > mySet; array<int, 3> array1 = { 1, 2, 3 }; array<int, 3> array2 = { 4, 5, 6 }; array<int, 3> array3 = { 1, 2, 3 }; // Insert arrays into the set mySet.insert(array1); mySet.insert(array2); mySet.insert(array3); // Iterate over the set for (auto& arr : mySet) { // Iterate over each element of the array for (auto& element : arr) { // Output each element followed by a space cout << element << ' '; } // Output a newline after each array cout << endl; } } Output1 2 3 4 5 6 Time Complexity: O(M * N log N), where N is the number of arrays and M is the average number of elements in the arrays.Auxiliary Space: O(N * M) Comment More infoAdvertise with us Next Article How to Create a Set of Arrays in C++? snx03 Follow Improve Article Tags : C++ Programs C++ STL cpp-array cpp-set CPP Examples +2 More Practice Tags : CPPSTL Similar Reads How to Create a Stack of Arrays in C++? In C++, the std::stack is a container that follows the LIFO (Last In, First Out) rule, whereas std::array is a sequence container that stores elements in contiguous memory. In this article, we will learn how to create a stack of an array in C++. Example: Input: arr1 = {1, 2, 3}; arr2 = {4, 5, 6}; ar 2 min read How to Create a Vector of Arrays in C++? In C++, an array is a collection of elements of a single type while vectors are dynamic arrays as they can change their size during the insertion and deletion of elements. In this article, we will learn how to create a vector of arrays in C++. Example: Input: arr1 = {1, 2, 3}; arr2 = {4, 5, 6}; arr3 2 min read How to Create an Array of Structs in C++? In C++, a struct is a user-defined data type that allows us to combine data of different types and an array of structs is an array in which each element is of the struct type. In this article, we will learn how to create an array of structs in C++. Creating an Array of Structs in C++To create an arr 2 min read How to Create Array of Arrays in C++ Arrays are basic C++ data structures that allow users to store the same data type in memory sequentially. To manage more complicated data structures, you may sometimes need to build an array of arrays, often called a 2D array or a matrix. In this article, we will learn how to create an array of arra 3 min read How to Create a Map of Arrays in C++? In C++, the std::map is a container that stores elements in a key-value pair, whereas std::array is a sequence container that stores elements in contiguous memory. In this article, we will learn how to create a map of arrays in C++. Example: Input: arr1 = {1, 2, 3};arr2 = {4, 5, 6};arr3 = {7, 8, 9}; 2 min read How to Create a Deque of Arrays in C++? In C++, a deque (double-ended queue) is a data structure that allows insertion and deletion at both ends whereas arrays are fixed-size collections of elements. In this article, we will learn how to create a deque of arrays in C++ STL. Example: Input: myArray1 = {1, 4, 8, 9, 11} myArray2 = {1, 2, 3, 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 Multimap of Arrays in C++? In C++, a multimap is similar to a map with the addition that multiple elements can have the same keys. Also, it is NOT required that the key-value and mapped value pair have to be unique in this case. In this article, we will learn how to create a multimap of arrays in C++ STL. Example Input: myArr 2 min read How to Create a Set of Pairs in C++? In C++, sets are associative containers that store unique elements. On the other hand, pairs allow the users to store two data of different or the same type into a single object. In this article, we will learn how we can create a set of pairs in C++. Example Input: p1={1, 2} p2 ={3, 4} Output: Eleme 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