|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--asd_library.tree.heap.Heap
The class Heap implements a max-heap
Field Summary | |
static int |
DEFAULTCAPACITY
|
Constructor Summary | |
Heap()
|
|
Heap(int dim)
|
Method Summary | |
static Heap |
array2heap(java.lang.Comparable[] data)
Build the heap from the specified array. |
java.lang.Comparable |
deleteFirst()
Deletes the first element stored in this heap. |
void |
exchange(int index,
int parent)
Exchanges the value stored in the position index e parent in this heap. |
java.lang.Comparable |
getFirst()
Returns the first element in this heap. |
int |
getMaxChildIndex(int parent)
Returns the child with the greatest value of the specified parent. |
int |
getSize()
Returns the number of elements in this heap. |
void |
heapify(int i)
Trickles down the node i until it reaches the position that reestablishes the heap order. |
static void |
heapSort(java.lang.Comparable[] data)
Sorting algorithm |
java.lang.Comparable |
insert(java.lang.Comparable key)
Inserts the specified element key in this heap. |
boolean |
isEmpty()
Verifies if this heap is empty |
boolean |
isFull()
Verifies if this heap is full |
boolean |
isLeaf(int i)
Verifies if the specified node i is a leaf. |
boolean |
isRoot(int i)
Verifies if the specified node i is the root. |
java.lang.String |
toString()
Returns a string representation of the heap. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int DEFAULTCAPACITY
Constructor Detail |
public Heap()
public Heap(int dim)
Method Detail |
public java.lang.Comparable getFirst()
getFirst
in interface PriorityQueue_adt
public java.lang.Comparable insert(java.lang.Comparable key)
insert
in interface PriorityQueue_adt
key
- element to insert.
public java.lang.Comparable deleteFirst()
deleteFirst
in interface PriorityQueue_adt
public void exchange(int index, int parent)
index
- position of an element in this heap.parent
- position of an element in this heap.public int getMaxChildIndex(int parent)
parent
- position of a node
public void heapify(int i)
i
- node to trickle down.public boolean isLeaf(int i)
i
- a node.
public boolean isRoot(int i)
i
- a node.
public boolean isEmpty()
public boolean isFull()
public int getSize()
public static void heapSort(java.lang.Comparable[] data)
data
- array to sortingpublic static Heap array2heap(java.lang.Comparable[] data)
data
- an array.
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |