T
- type of the objects in the heappublic class TopN<T> extends AbstractTopN<T>
capacity, size
Constructor and Description |
---|
TopN(int capacity)
Constructor that assumes that the class T implements the Comparable interface.
|
TopN(int capacity,
Comparator<T> cmp)
Constructor in which the comparator is specified.
|
Modifier and Type | Method and Description |
---|---|
protected int |
compare(int i,
int j)
Compares the i-th element of the heap with the j-th element in the heap.
|
protected int |
compare(int i,
T e)
Compares the i-th element of the heap with the element
|
protected T |
get(int i)
Returns the i-th element in the heap.
|
protected void |
set(int i,
T e)
Sets the element in the i-th position of the heap.
|
protected void |
swap(int i,
int j)
Swaps the elements in the i-th and j-th element in the heap.
|
add, iterator, peek, reverseIterator, reverseStream, size, sort
addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
equals, hashCode, parallelStream, removeIf, spliterator, stream
public TopN(int capacity)
capacity
- maximum capacity of the heappublic TopN(int capacity, Comparator<T> cmp)
capacity
- maximum capacity of the heapcmp
- comparatorprotected T get(int i)
AbstractTopN
get
in class AbstractTopN<T>
i
- index of the elementprotected void set(int i, T e)
AbstractTopN
set
in class AbstractTopN<T>
i
- indexe
- elementprotected int compare(int i, T e)
AbstractTopN
compare
in class AbstractTopN<T>
i
- indexe
- elementprotected int compare(int i, int j)
AbstractTopN
compare
in class AbstractTopN<T>
i
- indexj
- indexprotected void swap(int i, int j)
AbstractTopN
swap
in class AbstractTopN<T>
i
- indexj
- indexCopyright © 2016. All rights reserved.