How to get min or max element in a vector of structures in c++, based on some field in the structure?

前端 未结 5 1749
一整个雨季
一整个雨季 2021-02-05 08:24

How to get min or max element in a vector of structures in c++, based on some field in the structure?

For example:

struct Size {
    int width, height;
}         


        
5条回答
  •  眼角桃花
    2021-02-05 09:04

    Use std::min/std::max/std::minmax _element with comparator. http://en.cppreference.com/w/cpp/algorithm/min_element

提交回复
热议问题