How can I delete a specific element in priority queue?
Posted
by
Yuan
on Stack Overflow
See other posts from Stack Overflow
or by Yuan
Published on 2010-12-28T03:14:00Z
Indexed on
2010/12/28
3:53 UTC
Read the original article
Hit count: 186
java
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!
© Stack Overflow or respective owner