lower_bound == upper_bound

后端 未结 7 1021
陌清茗
陌清茗 2020-12-02 08:51

What does lower_bound mean. If I had to guess I would answer that this function returns the iterator at the last element that is less than the value asked for. But I see tha

7条回答
  •  Happy的楠姐
    2020-12-02 09:11

    lower_bound, upper_bound and equal_range are functions which perform binary search in a sorted sequence. The need for three functions comes from the fact that elements may be repeated in the sequence:

    1, 2, 3, 4, 4, 4, 5, 6, 7
    

    In this case, when searching for the value 4, lower_bound will return an iterator pointing to the first of the three elements with value 4, upper_bound will return an iterator pointing to the element with value 5, and equal_range will return a pair containing these two iterators.

提交回复
热议问题