|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnenok.lc.constr.vvll.Heap<C>
C
- Class implementing the Comparable
insterface.public class Heap<C extends Comparable>
This class offers a generic implementation of a binary
heap data structure. All elements need to implements the
Comparable
interface to guarantee that they can
be ordered to reconstruct the heap structure.
This heap implementation asserts that the smallest elements is
always on top of the heap and removed first. To determine the
smallest element, the operation compareTo(Object o)
from Comparable
is called.
Constructor Summary | |
---|---|
Heap()
Constructor: Creates a new empty heap. |
|
Heap(Collection<C> c)
Constructor: Creates a heap from a given collection of Comparable objects. |
Method Summary | |
---|---|
void |
add(C value)
Adds a single element to the heap. |
void |
add(Collection<C> c)
Adds a collection of elements to the heap. |
int |
getPosition(C c)
Returns the index of the given object in the heap. |
Iterator<C> |
iterator()
The iterator of the collection interface. |
C |
remove()
Removes the root (= smallest element) of the heap. |
int |
size()
Returns the number of elements contained in the heap. |
void |
update(int index)
Updates the heap, if the given node has changed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Heap()
public Heap(Collection<C> c)
Comparable
objects.
c
- The collection of heap elements.Method Detail |
---|
public void add(C value)
value
- The element to add.public void add(Collection<C> c)
c
- The collection of elements to add.public C remove()
public Iterator<C> iterator()
iterator
in interface Iterable<C extends Comparable>
public int size()
public void update(int index)
index
- The node to update.public int getPosition(C c)
c
- The object to search.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |