morey.spore
Class Heap

java.lang.Object
  |
  +--morey.spore.Heap
Direct Known Subclasses:
NoDupsHeap

public class Heap
extends java.lang.Object

This is an uninspired Heap.

Here is a link to the source code

See Also:
NoDupsHeap

Field Summary
protected  java.util.Vector data
           
 
Constructor Summary
Heap()
           
Heap(java.util.Enumeration e)
           
 
Method Summary
 void add(Comparable value)
          Add a comparable to the heap
protected  java.util.Enumeration elements()
          Give out the elements of the Heap
protected  java.lang.Object first()
          this is like a peek to see the first element.
protected  boolean isEmpty()
           
protected static int leftChildOf(int i)
          calculates the index of the leftChildOf the node at index i
protected static int parentOf(int i)
          calculates the index of the parent of the node at index i
protected  void percolateUp(int here)
          A value has been aded to the last level order position in the heap, destroying the heap property.
protected  void pushDown(int here)
          A value has been aded to the last level order position in the heap, destroying the heap property.
 void rebuild()
           
protected  java.lang.Object remove()
          this is like a peek to see the first element.
protected  void remove(java.lang.Object o)
          this is like a peek to see the first element.
protected static int rightChildOf(int i)
          calculates the index of the rightChildOf the node at index i
protected  int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected java.util.Vector data
Constructor Detail

Heap

public Heap()

Heap

public Heap(java.util.Enumeration e)
Method Detail

rebuild

public void rebuild()

parentOf

protected static int parentOf(int i)
calculates the index of the parent of the node at index i
Parameters:
i - the index of the child of the node we want the index of.
Returns:
the index of the parent (in the Vector)

leftChildOf

protected static int leftChildOf(int i)
calculates the index of the leftChildOf the node at index i
Parameters:
i - the index of the parent of the node we want the index of.
Returns:
the index of the left Child (in the Vector)

rightChildOf

protected static int rightChildOf(int i)
calculates the index of the rightChildOf the node at index i
Parameters:
i - the index of the parent of the node we want the index of.
Returns:
the index of the right child (in the Vector)

isEmpty

protected boolean isEmpty()
Returns:
true is the heap is Empty

size

protected int size()
Returns:
the size of the heap

first

protected java.lang.Object first()
this is like a peek to see the first element.
Returns:
the first element in the heap (the king of the castle)

add

public void add(Comparable value)
Add a comparable to the heap
Parameters:
value - is to be added to the heap

remove

protected java.lang.Object remove()
this is like a peek to see the first element.
Returns:
the first element in the heap (the king of the castle)

remove

protected void remove(java.lang.Object o)
this is like a peek to see the first element.
Returns:
the first element in the heap (the king of the castle)

percolateUp

protected void percolateUp(int here)
A value has been aded to the last level order position in the heap, destroying the heap property. percolateUp restores the heap property by pushing the new element up the tree to its correct location
Parameters:
here - is the new element's index

pushDown

protected void pushDown(int here)
A value has been aded to the last level order position in the heap, destroying the heap property. percolateUp restores the heap property by pushing the new element up the tree to its correct location
Parameters:
here - is the new element's index

elements

protected java.util.Enumeration elements()
Give out the elements of the Heap
Returns:
an Enumeration of the elements of the Heap