stl priority_queue of C++ with struct

后端 未结 3 913
野性不改
野性不改 2020-12-29 14:33

How can we use STL priority_queue for struct ? Any illustration of pushing & popping , where struct has multiple data-types?
Say :

3条回答
  •  死守一世寂寞
    2020-12-29 14:55

    You need to implement a compare function or overload operator to tell priority queue that on which order you want to sort your custom data. When priority queue will sort your data then it will need a way to know how to compare among them. You have to specify this by passing a function to priority queue or overloading operator in you custom data class or structure.

    You can check this answer. This might help you. I have tried to explain multiple ways of using priority queue for custom data types.

提交回复
热议问题