Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Unexpected behavior with PriorityQueue remove: Why isn't compareTo used?
- PriorityQueue<OwnClass> pq=new PriorityQueue<OwnClass>();
- OwnClass a=new OwnClass(1);
- OwnClass b=new OwnClass(2);
- OwnClass c=new OwnClass(3);
- pq.add(a);
- pq.add(b);
- pq.add(c);
- System.out.println("head:"+pq.peek());
- pq.remove(new OwnClass(1));
- System.out.println(pq.peek());
- class OwnClass implements Comparable{
- int x;
- public OwnClass(int x){
- this.x=x;
- }
- public int compareTo(Object arg0) {
- OwnClass a=(OwnClass) arg0;
- if(a.x>this.x)
- return -1;
- if(a.x<x)
- return 1;
- return 0;
- }
- public String toString(){
- return ""+x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment