![]() |
VOOZH | about |
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” }
Output:
Stack of Unordered_Multiset: [ { “orange”, “mango”, “orange” },
{ “apple”, “banana”, “apple” } ]
To create a stack of std::unordered_multiset in C++, first declare a std::stack with std::unordered_multiset as the template argument, then use the std::stack::push() function to insert the unordered_multiset in the stack.
stack<unordered_multiset<datatype>> stack_name;
Here,
The below program demonstrates how we can create and use a stack of unordered_multiset in C++ STL.
Elements in the Stack of Unordered_Multiset: orange orange mango apple apple banana
Time Complexity: O(N), here N is the total number of elements in each unordered_multiset.
Auxiliary Space:O(M * N), here M is the number of unordered_multiset.