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-bucket-function-in-c-stl/ below:

unordered_multiset bucket() function in C++ STL

unordered_multiset bucket() function in C++ STL

Last Updated : 02 Aug, 2018

The

unordered_multiset::bucket()

is a built-in function in C++ STL which returns the bucket number in which a given element is. Bucket size varies from 0 to

bucket_count-1. Syntax:
unordered_multiset_name.bucket(element)
Parameters:

The function accepts a single mandatory

element

which specifies the value whose bucket number is to be returned.

Return Value:

It returns an unsigned integral type which signifies the bucket number in which the element is. Below programs illustrates the above function:

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

int main()
{

    // declaration
    unordered_multiset<int> sample;

    // inserts element
    sample.insert(10);
    sample.insert(15);
    sample.insert(15);
    sample.insert(13);
    sample.insert(13);

    for (auto it = sample.begin(); it != sample.end(); it++) {
        cout << "The bucket number in which " << *it
             << " is " << sample.bucket(*it) << endl;
    }
    return 0;
}
Output:
The bucket number in which 13 is 6
The bucket number in which 13 is 6
The bucket number in which 10 is 3
The bucket number in which 15 is 1
The bucket number in which 15 is 1
Program 2: CPP
// C++ program to illustrate the
// unordered_multiset::bucket() 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('b');
    sample.insert('b');
    sample.insert('c');
    sample.insert('c');
    sample.insert('e');

    for (auto it = sample.begin(); it != sample.end(); it++) {
        cout << "The bucket number in which " << *it
             << " is " << sample.bucket(*it) << endl;
    }
    return 0;
}
Output:
The bucket number in which e is 16
The bucket number in which a is 12
The bucket number in which a is 12
The bucket number in which b is 13
The bucket number in which b is 13
The bucket number in which c is 14
The bucket number in which c is 14


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