更新时间:2023-10-02 22:56:34
this.y
和的相同比较替换返回0
obj.y
。
Replace return 0
by the same comparison algo on this.y
and obj.y
.
顺便说一下,在这里不需要重新分配 tmp
优化的图片可以是:
By the way, reassigning to tmp
is unnecessary here. The optimized picture can look like:
public int compareTo(Ponto other) {
if (this.x == other.x) {
return (this.y < other.y) ? -1 : ((this.y == other.y) ? 0 : 1);
} else {
return (this.x < other.x) ? -1 : 1;
}
}