C++ min heap with user-defined type.
- by bsg
Hi,
I am trying to implement a min heap in c++ for a struct type that I created. I created a vector of the type, but it crashed when I used make_heap on it, which is understandable because it doesn't know how to compare the items in the heap. How do I create a min-heap (that is, the top element is always the smallest one in the heap) for a struct type?
The struct is below:
struct DOC{
int docid;
double rank;
};
I want to compare the DOC structures using the rank member. How would I do this?
I tried using a priority queue with a comparator class, but that also crashed, and it also seems silly to use a data structure which uses a heap as its underlying basis when what I really need is a heap anyway.
Thank you very much,
bsg