|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.cosylab.util.Heap
public class Heap
Simple heap implementation. This implementation uses Comparable
interface to maintain ascending order. Heap will grow and shrink based on
number of elements. If total number of elements equals internal array size,
this array is expanded by factor of 2. If number of elements is less than
one quarter the array size, array will be shrunk to by half.
Implementation is synchronized and can be considered thread-safe.
Constructor Summary | |
---|---|
Heap()
Default constructor for Heap(). |
|
Heap(int initialSize)
Alternate constructor for heap that allows specification of initial size. |
Method Summary | |
---|---|
void |
add(java.lang.Comparable c)
Adds new element to the heap. |
java.lang.Comparable |
get(int index)
Returns element at index. |
java.lang.Comparable |
getFirst()
Returns smallest element or null if empty. |
boolean |
isEmpty()
True if heap is empty. |
static void |
main(java.lang.String[] args)
Run test applet. |
java.lang.Comparable |
remove()
Removes smallest element. |
int |
size()
Size of the heap. |
java.lang.String |
toString()
DOCUMENT ME! |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Heap()
public Heap(int initialSize)
initialSize
- Method Detail |
---|
public void add(java.lang.Comparable c)
c
- Element to add.public java.lang.Comparable remove()
public java.lang.Comparable get(int index)
index
- Index of the element.
public int size()
public boolean isEmpty()
public java.lang.Comparable getFirst()
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] args)
args
- command line parameters
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |