Hi.
Consider a set of integers S and an integer X.
How to find the maximum integer less than X in S using lower_bound and/or upper_bound?!
How to find the minimum integer greater than X in S using lower_bound and/or upper_bound?! Example :
S = {2 , 3 , 4 , 7 , 8 , 9} , X = 5
maximum integer less than 5 = 4
minimum integer grater than 5 = 7.
1)
2)
Good day to you!
Here are a few usages, too see, how to get elements around :)
i.e:
upper_bound finds first higher
lower_bound finds first higher/equal
You can use "--/++" to move around
PS: Beware of begin/end (not to "get" these elements) .. one can check by "==S.end()" / "S.begin()" :)
Hope I have not made any mistake ^_^
Good Luck!
Just to note: it is OK to dereference
begin()
, but you shouldn't do it withend()
. Also avoid doing--begin()
.Thanks haposiwe and -Morass- .
I didn't know --it works!