Finding smallest value in an array most efficiently

后端 未结 13 1682
慢半拍i
慢半拍i 2020-11-29 07:02

There are N values in the array, and one of them is the smallest value. How can I find the smallest value most efficiently?

13条回答
  •  借酒劲吻你
    2020-11-29 07:39

    The stl contains a bunch of methods that should be used dependent to the problem.

    std::find
    std::find_if
    std::count
    std::find
    std::binary_search
    std::equal_range
    std::lower_bound
    std::upper_bound
    

    Now it contains on your data what algorithm to use. This Artikel contains a perfect table to help choosing the right algorithm.


    In the special case where min max should be determined and you are using std::vector or ???* array

    std::min_element
    std::max_element
    

    can be used.

提交回复
热议问题