Code Fragment: compare



class LexCompare {					// lex comparison
public:
  int operator()(const Point2D& p1, const Point2D& p2) const {
    if	     (p1.getX() < p2.getX()) 		// first compare x
      return -1;
    else if  (p1.getX() > p2.getX()) 
      return +1;
    else if  (p1.getY() < p2.getY()) 		// x's equal; compare y
      return -1;
    else if  (p1.getY() > p2.getY()) 
      return +1;
    else 					// both x and y are equal
      return 0;
  }
};