Details
-
Task
-
Status: Closed
-
Resolution: Fixed
-
None
-
None
-
None
Description
In the current implementation offer(E e) of TopNSort.java
@SuppressWarnings("unchecked")
public boolean offer(E e)
{
if (q.size() <= qbound)
boolean ret = true;
boolean insert;
Comparable<? super E> head = (Comparable<? super E>)q.peek();
if (ascending)
{ // means head is the lowest value due to inversion insert = head.compareTo(e) <= 0; // e >= head }else
{ // means head is the highest value due to inversion insert = head.compareTo(e) >= 0; // head is <= e }if (insert && q.offer(e))
{ ret = true; q.poll(); } return ret;
}
the boolean variable ret should be initialized to false not true..