-3

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.

  • 3
    Please do not post images of code, or output. Place everything required in the question as text. – ChrisMM Aug 26 '21 at 10:15
  • [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/q/285551/995714). And why don't just read [`std::upper_bound`'s documentation](https://en.cppreference.com/w/cpp/algorithm/upper_bound) – phuclv Aug 26 '21 at 10:23
  • Does this answer your question? [rationale for std::lower\_bound and std::upper\_bound?](https://stackoverflow.com/questions/23554509/rationale-for-stdlower-bound-and-stdupper-bound) – prehistoricpenguin Aug 26 '21 at 10:49

1 Answers1

2

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.

ChrisMM
  • 8,448
  • 13
  • 29
  • 48