c++algorithmupperbound

what do upper_bound() do?


I am begineer and I dont understand the following.

In the code code

I got the output

output

Now my question is since the upper_bound() operator gives the index of greater value how did the output gave the answer of upperbound as 7 and not 1.


Solution

  • Both the upper_bound and lower_bound functions require the range to be partitioned according to the value you are looking for, essentially being sorted. Since your vector does not meet this criterion, you cannot expect logical results.