0

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?

4

1 回答 1

2

lower_bound返回

一个迭代器,指向范围内[first, last)小于(即大于或等于)值的第一个元素。

有关更多详细信息,请参见此处:lower_bound - cppreference

于 2016-11-13T22:39:33.150 回答