public class Heap
extends java.lang.Object
The class currently uses a standard array-based heap, as described in, for example, Sedgewick's Algorithms text. All methods are fully synchronized. In the future, it may instead use structures permitting finer-grained locking.
Modifier and Type | Field and Description |
---|---|
protected int |
count |
protected java.lang.Object[] |
nodes |
protected SortTool |
tool |
Constructor and Description |
---|
Heap(int capacity) |
Heap(int capacity,
SortTool tool) |
Heap(Set<java.lang.Object> set,
SortTool tool) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
remove all elements
|
java.lang.Object |
extract()
Return and remove least element, or null if empty
|
java.lang.Object |
getItem(int i)
returns the i-th object in the binary heap.
|
java.lang.Object[] |
getObjects() |
int |
getSize() |
void |
insert(java.lang.Object x) |
boolean |
isEmpty()
returns true if the heap is empty.
|
protected int |
left(int k) |
static void |
main(java.lang.String[] args) |
protected int |
parent(int k) |
java.lang.Object |
peek()
Return least element without removing it, or null if empty
|
protected int |
right(int k) |
void |
setItem(int i,
java.lang.Object x) |
void |
siftDown(int k) |
void |
siftUp(int k) |
int |
size()
Return number of elements
|
protected java.lang.Object[] nodes
protected int count
protected SortTool tool
public Heap(int capacity, SortTool tool) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public Heap(int capacity)
protected final int parent(int k)
protected final int left(int k)
protected final int right(int k)
public java.lang.Object[] getObjects()
public boolean isEmpty()
public int getSize()
public java.lang.Object getItem(int i)
i
- public void setItem(int i, java.lang.Object x)
public void siftUp(int k)
public void siftDown(int k)
public void insert(java.lang.Object x)
public java.lang.Object extract()
public java.lang.Object peek()
public int size()
public void clear()
public static void main(java.lang.String[] args)
args
-