lower_bound(): This is a build-in function in STL. This function finds the beginning of a subsequence matching given key. This function returns an iterator pointing to the first element
equal to or greater than key, or end().
This function returns the first element of a subsequence of elements that match the given key. If unsuccessful it returns an iterator pointing to the first element that has a greater value than the given key or end() if no such element exists.
Parameters: One parameter is required for this function.
__x – Key to being located.
Syntax:
set<data_type>::iterator it = st.lower_bound(__x)
For Example:
st = {1,19,5,2}
st.lower_bound(3) = > It returns iterator pointing to 5.
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){set<int> st;st.insert({1, 19, 5, 2});set<int>::iterator it = st.lower_bound(3);cout << *it << "\n";return 0;}
No comments:
Post a Comment