Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14.3 #241

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

14.3 #241

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/main/java/com/github/hcsp/polymorphism/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Point {
public class Point implements Comparable<Point>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'>' 后字符不合法。
'{' 前应有空格。


private final int x;
private final int y;
Expand Down Expand Up @@ -53,7 +54,10 @@ public String toString() {

// 按照先x再y,从小到大的顺序排序
// 例如排序后的结果应该是 (-1, 1) (1, -1) (2, -1) (2, 0) (2, 1)
public static List<Point> sort(List<Point> points) {}
public static List<Point> sort(List<Point> points) {
Collections.sort(points);
return points;
}

public static void main(String[] args) throws IOException {
List<Point> points =
Expand All @@ -65,4 +69,21 @@ public static void main(String[] args) throws IOException {
new Point(2, -1));
System.out.println(Point.sort(points));
}

@Override
public int compareTo(Point point) {
if(this.x<point.x){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'if' 后应有空格。
'<' 后应有空格。
'<' 前应有空格。
'{' 前应有空格。

return -1;
}
if(this.x>point.x){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'if' 后应有空格。
'>' 后应有空格。
'>' 前应有空格。
'{' 前应有空格。

return 1;
}
if(this.y<point.y){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'if' 后应有空格。
'<' 后应有空格。
'<' 前应有空格。
'{' 前应有空格。

return -1;
}
if(this.y>point.y){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'if' 后应有空格。
'>' 后应有空格。
'>' 前应有空格。
'{' 前应有空格。

return 1;
}
return 0;
}
}