Comparator<struc> cmp= new Comparator<struc>() {
public int compare(struc e1, struc e2) {
return e1.x - e2.x;
}
};
struc is point structure. when I offer:
(3,1)(3,2)(3,3)(3,4)
q gives me:
(3,1)(3,4),(3,3)(3,2)
and when I offer:
(3,1)(3,3)(3,2)(3,4)
it gives me:
(3,1)(3,4),(3,2)(3,3).
What's the logic?
Should it just give the order of key_in sequence since y is not compared?
When I checked API,it tells me "An unbounded priority queue based on a priority heap...The head of this queue is the least element with respect to the specified ordering. If multiple elements are tied for least value, the head is one of those elements -- ties are broken arbitrarily."
Can someone help explain?
struc, and the code you use to put/retrieve the values in the queue. Are you iterating the values using anIterator, or are you usingpoll()to get/remove the head every time ?