我的程序打印主构造函数,但不返回 3 个底部函数,而是返回它的编译。我哪里错了?
import java.util.*;
public class Main {
public static void main(String[] args) {
PriorityQueue<String> queue1 = new PriorityQueue<String>();
System.out.println(" ");
//Adding strings to queue1
queue1.offer("Goerge");
queue1.offer("Jim");
queue1.offer("John");
queue1.offer("Blake");
queue1.offer("Kevin");
queue1.offer("Michael");
System.out.println("Priority queue using Comparable:");
while (queue1.size() > 0) {
System.out.print(queue1.remove() + " ");
}
PriorityQueue<String> queue2 = new PriorityQueue<String>(4,
Collections.reverseOrder());
System.out.println(" ");
//Adding strings to queue2
queue2.offer("George");
queue2.offer("Katie");
queue2.offer("Kevin");
queue2.offer("Michelle");
queue2.offer("Ryan");
System.out.println("\nPriority queue using Comparator:");
while (queue2.size() > 0) {
System.out.print(queue2.remove() + " ");
}
}
public static PriorityQueue<String> union(PriorityQueue<String> queue1, PriorityQueue<String> queue2){
PriorityQueue<String> queue3 = new PriorityQueue<>();
queue3.addAll(queue1);
queue3.addAll(queue2);
return queue3;
}
public static PriorityQueue<String> intersection(PriorityQueue<String> queue1, PriorityQueue<String> queue2) {
PriorityQueue<String> queue3 = new PriorityQueue<>(queue1);
queue3.retainAll(new HashSet<>(queue2));
return queue3;
}
public static PriorityQueue<String> difference(PriorityQueue<String> q1, PriorityQueue<String> intersectionQueue) {
PriorityQueue<String> q3 = new PriorityQueue<>(q1);
q3.removeAll(new HashSet<>(intersectionQueue));
return q3;
}
}
这 3 个函数必须返回 2 个队列的并集、差集和交集。但它们没有显示在输出中。