Lower_bound in set (C ++)

I have a set and I want to find the largest number, not more than x in it. (something like lower_bound (x)), how should I do this? Are there any predefined functions?

set<int> myset;
myset.insert(blahblahblah);
int y;
//I want y to be greatest number in myset not greater than x
+3
source share
2 answers

You can use upper_boundthe following way: upper_bound(x)--. The upper bound gives you the first element to exceed x, so the element you are looking for is the one that was before. You need a special case if upper_boundreturns begin().

+1
source

In addition to lower_bound, there is also upper_bound C ++ Link

, . begin(), , , .

0

Source: https://habr.com/ru/post/1770274/


All Articles