A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/cpp/unordered_multiset-count-function-in-c-stl/ below:

unordered_multiset count() function in C++ STL

unordered_multiset count() function in C++ STL

Last Updated : 02 Aug, 2018

The

unordered_multiset::count()

is a built-in function in C++ STL which returns the count of elements in the unordered_multiset container which is equal to a given value.

Syntax:
unordered_multiset_name.count(val)
Parameters:

The function accepts a single mandatory parameter

val

which specifies the element whose count in the unordered_multiset container is to be returned.

Return Value:

It returns an unsigned integral type which denotes the number of times a

value

occurs in the container. Below programs illustrates the above function:

Program 1: CPP
// C++ program to illustrate the
// unordered_multiset::count() function
#include <bits/stdc++.h>
using namespace std;

int main()
{

    // declaration
    unordered_multiset<int> sample;

    // inserts element
    sample.insert(11);
    sample.insert(11);
    sample.insert(11);
    sample.insert(12);
    sample.insert(13);
    sample.insert(13);
    sample.insert(14);

    cout << "11 occurs " << sample.count(11) << " times";
    cout << "\n12 occurs " << sample.count(13) << " times";
    cout << "\n13 occurs " << sample.count(13) << " times";
    cout << "\n14 occurs " << sample.count(14) << " times";

    return 0;
}
Output:
11 occurs 3 times
12 occurs 2 times
13 occurs 2 times
14 occurs 1 times
Program 2: CPP
// C++ program to illustrate the
// unordered_multiset::count() function
#include <bits/stdc++.h>
using namespace std;

int main()
{

    // declaration
    unordered_multiset<char> sample;

    // inserts element
    sample.insert('a');
    sample.insert('a');
    sample.insert('a');
    sample.insert('b');
    sample.insert('b');
    sample.insert('c');
    sample.insert('c');

    cout << "a occurs " << sample.count('a') << " times";
    cout << "\nb occurs " << sample.count('b') << " times";
    cout << "\nc occurs " << sample.count('c') << " times";

    return 0;
}
Output:
a occurs 3 times
b occurs 2 times
c occurs 2 times


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4