public static class MyComp implements Comparator<Integer>{
@Override
public int compare(Integer o1, Integer o2) {
return o2 - o1;
}
}
- 若compare返回负数,o1在o2前
- 若compare返回0,相等
- 若compare返回正数,o2在o1前
使用
Arrays.sort(arr, new AComp());
PriorityQueue<Student> heap = new PriorityQueue<>(new StudentComparator());
Comments | 0 条评论