unordered_multiset begin() function in C++ STL
The unordered_multiset::begin() is a built-in function in C++ STL which returns an iterator pointing to the first element in the container or to the first element in one of its bucket.
Syntax:
unordered_multiset_name.begin(n)
Parameters: The function accepts one parameter. If a parameter is passed, it returns an iterator pointing to the first element in the bucket. If no parameter is passed, then it returns an iterator pointing to the first element in the unordered_multiset container.
Return Value: It returns an iterator.
Below programs illustrates the above function:
Program 1:
// C++ program to illustrate the // unordered_multiset::begin() function #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multiset<int> sample; // inserts element sample.insert(10); sample.insert(11); sample.insert(15); sample.insert(13); sample.insert(14); // print the first element cout << "The first element: " << *sample.begin(); cout << "\nElements: "; // prints all element for (auto it = sample.begin(); it != sample.end(); it++) cout << *it << " "; return 0; } |
The first element: 14 Elements: 14 13 15 10 11
Program 2:
// C++ program to illustrate the // unordered_multiset::begin() function #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multiset<char> sample; // inserts element sample.insert('a'); sample.insert('b'); sample.insert('c'); sample.insert('x'); sample.insert('z'); // print the first element auto it = sample.begin(); cout << "The first element: " << *it; it++; cout << "\nThe second element: " << *it; cout << "\nElements: "; // prints all element for (auto it = sample.begin(); it != sample.end(); it++) cout << *it << " "; return 0; } |
The first element: z The second element: x Elements: z x c a b
Program 3:
// C++ program to illustrate the // unordered_multiset::begin() function #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multiset<char> sample; // inserts element sample.insert('a'); sample.insert('b'); sample.insert('c'); sample.insert('x'); sample.insert('z'); // print the first element cout << "The first element in first bucket : " << *sample.begin(1); cout << "\nElements in first bucket: "; // prints all element for (auto it = sample.begin(1); it != sample.end(1); it++) cout << *it << " "; return 0; } |
The first element in first bucket : x Elements in first bucket: x c
Recommended Posts:
- unordered_set begin() function in C++ STL
- match_results begin() and end() function in C++ STL
- valarray begin() function in C++
- unordered_multimap begin() and end() function in C++ STL
- multiset begin() and end() function in C++ STL
- map::begin() and end() in C++ STL
- set::begin() and set::end() in C++ STL
- unordered_map begin() in C++
- array::begin() and array::end() in C++ STL
- vector::begin() and vector::end() in C++ STL
- list::begin() and list::end() in C++ STL
- forward_list::begin() and forward_list::end() in C++ STL
- multimap::begin() and multimap::end() in C++ STL
- deque::begin() and deque::end in C++ STL
- Function Overloading vs Function Overriding in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



