unordered_set bucket() in C++

bucket(): This function is available in the File unordered_set.h

Syntax:

std::size_t std::unordered_set<int>::bucket(const int &__key) const

This function takes an argument of type int as its parameter. This function returns the bucket index of a given element.

Parameters: One parameter is required for this method.

__key – A key instance. 

Returns: The key bucket index.

For Example:

st = {9,4}

key = 4

st.bucket(key) = > It return 1.

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    unordered_set<intst;
    st.insert(9);
    st.insert(4);

    int key = 4;

    cout << st.bucket(key<< "\n";

    return 0;
}

Output:

1

No comments:

Post a Comment