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

Constructor Index

 o Heap(Heapable[], boolean)
Constructs the heap by copying an unordered array.
 o Heap(Heapable[])
Constructs the heap by copying an unordered array.
 o Heap(boolean)
Constructs a heap with the given sorting order.
 o Heap()
Constructs a heap with keys sorted in descending order.

Method Index

 o clear()
Removes all keys from the heap.
 o insert(Heapable)
Inserts a key into the heap.
 o isEmpty()
Returns true if there are no keys in the heap, false otherwise.
 o remove()
Removes the top key from the heap.
 o size()
Returns the number of keys in the heap.
 o visualize(TreeGraphics)
Visualizes every key in the heap using calls to TreeGraphics.

Constructors

 o 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.
 o Heap
  public Heap(Heapable anArray[])
Constructs the heap by copying an unordered array. Sorts keys in descending order. Takes O(N) time.
 o 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.
 o Heap
  public Heap()
Constructs a heap with keys sorted in descending order. Takes O(N) time.

Methods

 o isEmpty
  public boolean isEmpty()
Returns true if there are no keys in the heap, false otherwise. Takes O(1) time.
 o size
  public int size()
Returns the number of keys in the heap. Takes O(1) time.
 o clear
  public synchronized void clear()
Removes all keys from the heap. Takes O(N) time.
 o remove
  public synchronized Heapable remove() throws NoSuchElementException
Removes the top key from the heap. Takes O(N log N) time.
 o insert
  public synchronized void insert(Heapable key)
Inserts a key into the heap. Takes O(N log N) time.
 o 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