Unordered_multiset ::bucket() es una función integrada en C++ STL que devuelve el número de depósito en el que se encuentra un elemento determinado. El tamaño del depósito varía de 0 a bucket_count-1.
Sintaxis:
unordered_multiset_name.bucket(element)
Parámetros: la función acepta un solo elemento obligatorio que especifica el valor cuyo número de depósito se devolverá.
Valor de retorno: Devuelve un tipo integral sin signo que significa el número de cubo en el que se encuentra el elemento.
Los siguientes programas ilustran la función anterior:
Programa 1:
// 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; }
Producción:
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
Programa 2:
// 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; }
Producción:
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