|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--u6.Heap
Abstract Heap
class.
A heap is a binary tree that stores a collection of keys at its internal
nodes and that satisfies two additional properties:
1. Heap-Order Property: for every node v
other than the root
the key stored at v
is greater than or equal to the key stored
at v
's parent.
2. Complete Binary Tree: the levels 0, 1, ... (height - 1) have the maximum
number of nodes possible and in level (height - 1) all the nodes are to the
left.
Field Summary | |
protected java.util.Comparator |
cmp
Comparator, defining a total relation on the keys |
protected int |
height
The height of the heap; a heap with one element has height = 1. |
protected int |
size
The number of elements in this heap |
Constructor Summary | |
Heap(java.util.Comparator cmp)
Constructs an empty heap with the given comparator. |
Method Summary | |
abstract void |
add(Item entry)
Adds the given item in the heap and updates the size and the height values. |
void |
add(java.lang.Object key,
java.lang.Object value)
Adds a node with the given key and value in the heap
and updates the size and the height values. |
static int |
computeHeight(int size)
Computes the height of a heap with a given size. |
abstract Item |
extractItem()
Extracts the root of the Heap and updates the size and the height values. |
int |
getHeight()
Reads the height of the heap. |
boolean |
isEmpty()
Checks whether the heap is empty. |
abstract java.lang.Object |
readMinElement()
Reads the element value of the item, stored in the root of the heap without removing the root. |
abstract java.lang.Object |
readMinKey()
Reads the key, stored in the root of the heap, without extracting the root. |
int |
size()
Reads the number of items stored in the heap. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected int size
protected int height
protected java.util.Comparator cmp
Constructor Detail |
public Heap(java.util.Comparator cmp)
Method Detail |
public void add(java.lang.Object key, java.lang.Object value)
key
and value
in the heap
and updates the size
and the height
values.public abstract void add(Item entry)
size
and the height
values.public abstract Item extractItem()
size
and the height
values.public abstract java.lang.Object readMinKey()
public abstract java.lang.Object readMinElement()
public int size()
public int getHeight()
public boolean isEmpty()
public static int computeHeight(int size)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |