easy way to maintain a min heap with stl?

后端 未结 3 1314
一生所求
一生所求 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:01

    You shouldn't need to overload operator < for int (you can't, actually). If you use an external comparator, you should be passing the same Comparator comp to pop_head as well.

    * Edit: *

    As ildjarn pointed out, your comparison operator does not implement a strict-weak-ordering relation.

    a < b ? false : true; --> a >= b
    b < a ? true : false; --> a > b
    

提交回复
热议问题