class info2 implements Comparable<info2>{
int x, y,dist;
public info2(int x, int y ,int dist) {
this.x = x;
this.y = y;
this.dist=dist;
}
public int compareTo(info2 o) {
int compare =Integer.compare(this.dist, o.dist);
if(compare ==0) {
compare = Integer.compare(this.x, o.x);
if(compare ==0) {
compare = Integer.compare(this.y, o.y);
}
}
return compare;
}
}
자바는 이런 정렬이 가능하다. 구조체 정렬은 필 수 템이란 것을 잊지말도록 하자!
'SAFFY' 카테고리의 다른 글
Greedy알고리즘 (0) | 2022.08.28 |
---|---|
7월 28일 (0) | 2022.07.28 |
7월 27일 (0) | 2022.07.27 |
7월 26일 (0) | 2022.07.26 |