How can I delete a specific element in priority queue?
- by Yuan
import java.util.*;
public class test4 {
public static void main(String[] args){
PriorityQueue[] P = new PriorityQueue[10];
P[1] = new PriorityQueue<ClassEntry>();
P[1].add(new ClassEntry(1.2,1));
P[1].add(new ClassEntry(1.5,2));
P[1].add(new ClassEntry(1.2,3));
P[1].add(new ClassEntry(10,4));
P[1].remove(new ClassEntry(10,4));//I can't delete this object???
System.out.println(P[1].size());
ClassEntry ce = (ClassEntry) P[1].peek();
System.out.println(P[1].size());
System.out.println(ce.sim+"\t"+ce.index);
}
}
Why i can't delete (10,4)? Can somebody teach how to implement...thanks!