![]() |
In C++, a multiset is a container that stores elements in a sorted order and multiple elements can have the same values. In this article, we will learn how to find the frequency of a specific element in a multiset. Example: Input: myMultiset = { 5,2,8,5,8,8} Element: 8 Output: Frequency of 8 is: 3 Finding Frequency of an Element in Multiset in C++To find the frequency of a specific element in a std::multiset in C++, we can use the std::multiset::count() function that returns the number of times the given element occurs within the multiset. C++ Program to Find the Frequency of an Element in a MultisetThe below example demonstrates the use of multiset::count() function to find the frequency of a specific element in a multiset in C++. C++
Output
Frequency of 8 in the multiset: 2 Time Complexity: O(log(N))
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |