Please tell me what upper_bound
and lower_bound
are in the C++ Standard Library and how they work.
Answer 1, authority 100%
Well, for example, you have a ordered (important!) sequence
1 2 3 4 4 4 5 5 5 5 5 6 7
When looking for upper_bound
for a value of 5 this there will be an iterator (a pointer if the concept of an iterator is new to you) to the value 6 – the first larger value .
Accordingly, lower_bound
will point to the first not less value – the first 5.
For example code
int main (int argc, const char * argv [])
{
int a [20] = {1,2,3,4,5,6,7,7,7,7,8,9,9,11,11,12,16,20,20,20,20};
for (int * p = lower_bound (a, a + 20,10);
p! = upper_bound (a, a + 20.20); ++ p)
cout & lt; & lt; * p & lt; & lt; "";
cout & lt; & lt; endl;
}
gives
11 11 12 16 20 20 20 20