I have the below struct:
struct node {
float val;
int count;
}
I have several objects of this struct. Now, I want to insert these objects into a priority queue of STL such that the priority queue orders the items by count. Any idea on how to do so? Preferably a min-heap is preferred. I know how to do the above for primitive data types, not structs
Overload the < operator:
I have reversed the comparison to achieve min heap without passing extra arguments to the priority queue.
Now you use it like this:
Edit: take a look at this post which seems to be almost exact duplicate: STL Priority Queue on custom class