Reputation: 2684
I am a noob to c++, I just came across this code
x = v[lft]+k;
low = lower_bound(v.begin(), v.end(), x) - v.begin();
if(low >= n|| v[low] > x )
low--;
center = v[low];
if x is not present in the vector, it returns a value greater than the size of the vector. That justifies searching whether low >= n
, but I cant figure out under which circumstance will this condition v[low] > x
satisy?Should'nt low
be an index in which x is present, so how can there be a value greater than x?
Upvotes: 0
Views: 830
Reputation: 517
lower_bound
returns
an iterator pointing to the first element in the range
[first, last)
that is not less than (i.e. greater or equal to) value.
See here for more detail: lower_bound - cppreference
Upvotes: 2