Created
February 19, 2015 22:22
-
-
Save rainiera/1a9bc406dc2920eab13d to your computer and use it in GitHub Desktop.
example of PointDistance class for "KClosestPoints" problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PointDistance implements Comparable<PointDistance> { | |
Point p; | |
double dist; | |
public PointDistance(Point p, double dist) { | |
this.p = p; | |
this.dist = dist; | |
} | |
public int compareTo(PointDistance other) { | |
return (int) (this.dist - other.dist); | |
} | |
// I could fix the toString to display a comma. | |
// Easy fencepost stuff. | |
// I will leave it as an exercise to the reader. | |
public String toString() { | |
return "(" + (int) p.getX() + ", " + (int) p.getY() + ") "; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment