这样一段程序:
public static void main(String[] args) {
int[] reward = new int[]{1, 4, 4, 6, 4};
Queue<Integer> q1 = new PriorityQueue<>();
Queue<Integer> q2 = new PriorityQueue<>((a, b) -> b - a);
for (int j : reward) {
q1.add(j);
}
for (int j : reward) {
q2.add(j);
}
System.out.println(q1);//[1, 4, 4, 6, 4]
System.out.println(q2);//[6, 4, 4, 1, 4]
}
请教各位,为什么会排序错误
public static void main(String[] args) {
int[] reward = new int[]{1, 4, 4, 6, 4};
Queue<Integer> q1 = new PriorityQueue<>();
Queue<Integer> q2 = new PriorityQueue<>((a, b) -> b - a);
for (int j : reward) {
q1.add(j);
}
for (int j : reward) {
q2.add(j);
}
System.out.println(q1);//[1, 4, 4, 6, 4]
System.out.println(q2);//[6, 4, 4, 1, 4]
}
请教各位,为什么会排序错误
