Class mjr.heap.Heap
All Packages Class Hierarchy This Package Previous Next Index
Class mjr.heap.Heap
java.lang.Object

+mjr.heap.Heap
 public class Heap
 extends Object
A priority queue according to Cormen, Leiserson and Rivest.
The heap can be constructed in O(N) time by copying an array, or
O(N log N) time by staring with an empty heap and performing N
insertions.
The heap is visualized with a call to TreeGraphics.
 See Also:
 TreeGraphics

Heap(Heapable[], boolean)
 Constructs the heap by copying an unordered array.

Heap(Heapable[])
 Constructs the heap by copying an unordered array.

Heap(boolean)
 Constructs a heap with the given sorting order.

Heap()
 Constructs a heap with keys sorted in descending order.

clear()
 Removes all keys from the heap.

insert(Heapable)
 Inserts a key into the heap.

isEmpty()
 Returns true if there are no keys in the heap, false otherwise.

remove()
 Removes the top key from the heap.

size()
 Returns the number of keys in the heap.

visualize(TreeGraphics)
 Visualizes every key in the heap using calls to TreeGraphics.
Heap
public Heap(Heapable anArray[],
boolean descending)
 Constructs the heap by copying an unordered array. Sorts keys
in descending order if descending is true, ascending order
otherwise. Takes O(N) time.
Heap
public Heap(Heapable anArray[])
 Constructs the heap by copying an unordered array. Sorts keys
in descending order. Takes O(N) time.
Heap
public Heap(boolean descending)
 Constructs a heap with the given sorting order. Takes O(N) time.
 Parameters:
 descending  true if keus should be sorted in descending order.
Heap
public Heap()
 Constructs a heap with keys sorted in descending order.
Takes O(N) time.
isEmpty
public boolean isEmpty()
 Returns true if there are no keys in the heap, false otherwise.
Takes O(1) time.
size
public int size()
 Returns the number of keys in the heap.
Takes O(1) time.
clear
public synchronized void clear()
 Removes all keys from the heap.
Takes O(N) time.
remove
public synchronized Heapable remove() throws NoSuchElementException
 Removes the top key from the heap.
Takes O(N log N) time.
insert
public synchronized void insert(Heapable key)
 Inserts a key into the heap.
Takes O(N log N) time.
visualize
public void visualize(TreeGraphics tg)
 Visualizes every key in the heap using calls to TreeGraphics.
Takes O(N) time.
All Packages Class Hierarchy This Package Previous Next Index