I have written the following class:
public class SortingObjectsWithAngleField implements Comparator<Point> {
public int compare(Point p1, Point p2) {
double delta = p1.getAngle() - p2.getAngle();
if(delta == 0.00001)
return 0;
return (delta > 0.00001) ? 1 : -1;
}
}
Then, in my main()
method, I have created a List
to which I add some objects which has "X" and "angle" field.
I then use:
Collections.sort(list, new SortingObjectsWithAngleField());
What is the complexity of this sort method?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…