easy way to maintain a min heap with stl?

后端 未结 3 1313
一生所求
一生所求 2021-02-01 06:32

for user defined struct, as I understand, it\'s easy. Just overload the operator <. However, for int/float etc.., do I really need to overload operator < for int? Here is

3条回答
  •  盖世英雄少女心
    2021-02-01 07:08

    Use std::greater() as the comparator(to all of make_heap, push_heap, pop_heap). The () are important - std::greater is a functor class not a function, so you need an instance of it.

提交回复
热议问题