I know how does heap work and how it arranges min and max elements. It is easy, if vector contains only int
, to apply make_heap in STL. But how to apply make_heap()
if vector contains structure of string and int. Iwant to make heap based on int
value in structure.
Please tell me how to do that.
You have to provide comparison function for your structure:
struct A
{
int x, y;
};
struct Comp
{
bool operator()(const A& s1, const A& s2)
{
return s1.x < s2.x && s1.y == s2.y;
}
};
std::vector<A> vec;
std::make_heap(vec.begin(), vec.end(), Comp());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With