end(): This function is available in the File: unordered_set.h
Syntax:
std::unordered_set<int>::iterator std::unordered_set<int>::end()
This function returns a read-only (constant) iterator that points one past the last element in the unordered_set.
The iterator returned by the end does not point to any element, but to the position that follows the last element in the unordered_set container. Thus, the value returned shall not be dereferenced.
Parameters: This function takes one parameter (or it does not take any parameter).
File: unordered_set.h
Approach 1: When the function does not take any argument.
C++
#include <bits/stdc++.h>using namespace std;int main(){unordered_set<int> st = {3, 12, 45, 3, 10};for (auto it = st.begin(); it != st.end(); it++)cout << *it << " ";return 0;}
Output:
12 10 45 3
Approach 2: When the function takes an argument.
C++
#include <bits/stdc++.h>using namespace std;int main(){unordered_set<int> st = {3, 12, 45, 3, 10};for (int i = 0; i < st.bucket_count(); i++){cout << "Bucket " << i << " contains: ";for (auto it = st.begin(i); it != st.end(i); it++)cout << *it << " ";cout << "\n";}return 0;}
Output:
Bucket 0 contains: Bucket 1 contains: Bucket 2 contains: Bucket 3 contains: 10 45 3 Bucket 4 contains: Bucket 5 contains: 12 Bucket 6 contains:
No comments:
Post a Comment