end(): This function is a build-in function in STL. This function returns a
read-only (constant) iterator that points one past the last element in the set.
Note: Iteration is done in ascending order according to the keys.
This function is available in the below file.
File: stl_set.h
Parameters: No parameters are required for this function.
Syntax:
set<data_type>::iterator it = st.end()
For Example:
st = {1,2,3,4}
st.end() = > It returns an iterator to the last element (i.e 4).
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){set<int> st;st.insert(4);st.insert(2);st.insert(3);st.insert(1);set<int>::iterator it = st.end();cout << *it << "\n";return 0;}
No comments:
Post a Comment