Priority_Queue Custom Comparator in C++

I have a Point Class and am creating a min-heap of Point objects.

class Point
{
   int x;
   int y;
public:
   Point(int _x, int _y)
   {
      x = _x;
      y = _y;
   }
   int getX() const { return x; }
   int getY() const { return y; }
};
 
// To compare two points
class myComparator
{
public:
    int operator() (const Point& p1, const Point& p2)
    {
        return p1.getX() > p2.getX();
    }
};

If I want to create a min-heap why is it p1.getX() > p2.getX() and not p1.getX() < p2.getX() since I think p1 is the parent and p2 is the child. Please clear my confusion.

Comments (0)