Class PartialSort<T>

  • Type Parameters:
    T -

    public class PartialSort<T>
    extends Object
    Sorts from smallest to largest. If the opposite should be the case then add elements with their values negated: PartialSort.add(element, -value). Works fine for small k (k << n); otherwise, one should consider a partial version of heapsort or quicksort.

    More info: Partial sorting

    • Method Detail

      • add

        public void add​(T element,
                        double value)
      • kSmallestElements

        public List<TkSmallestElements()
        Gets k smallest elements (side effect: they are removed from the queue -- the queue gets empty).
        Returns:
        list containing k smallest elements sorted ascending: from the smallest to the k-th smallest