Selecting the maximum “n” values

前端 未结 3 1127
挽巷
挽巷 2021-01-25 16:43

If I have the following:

#include 
#include 
#include 
#include 

    struct Features{ int F1, F2,         


        
3条回答
  •  花落未央
    2021-01-25 17:07

    With a combination of std::transform, std::multiset, and an insert iterator you could.

    vector v;
    ...fill it up
    multiset ms;
    transform(v.begin(), v.end(), inserter(ms, ms.begin()), criterionFunction);
    

    Then the three max values are the last three elements.

提交回复
热议问题