rationale for std::lower_bound and std::upper_bound?

后端 未结 10 1538
傲寒
傲寒 2021-01-30 08:13

STL provides binary search functions std::lower_bound and std::upper_bound, but I tend not to use them because I\'ve been unable to remember what they do, because their contract

10条回答
  •  臣服心动
    2021-01-30 08:54

    For an array or vector :

    std::lower_bound: Returns an iterator pointing to the first element in the range that is

    • less than or equal to value.(for array or vector in decreasing order)
    • greater than or equal to value.(for array or vector in increasing order)

    std::upper_bound: Returns an iterator pointing to the first element in the range that is

    • less than value.(for array or vector in decreasing order)

    • greater than value.(for array or vector in increasing order)

提交回复
热议问题