Unlike java.util.TreeSet, this data structure can handle duplicate entries. The implementations of the methods given here implement a MinHeap. It is abstract so that we can have a MinHeap class that supports deleteMin() and a MaxHeap class that supports deleteMax() but neither of them support both.
Definition at line 45 of file Heap.java.
Public Methods | |
Heap () | |
Creates an empty Heap. | |
Heap (Comparator c) | |
Use given Comparator for all comparisons between elements in this Heap. | |
Heap (int capacity) | |
Creates an empty Heap with the given capacity. | |
Heap (Collection c) | |
Create a new Heap containing the elements of the given Collection. | |
Object | remove (int index) |
Remove the Object at the given index from the Heap. | |
boolean | remove (Object o) |
Remove the Object o from the Heap and return true. | |
boolean | add (Object o) |
Add o to the Heap. | |
boolean | addAll (Collection c) |
Add the contents of a Collection to the Heap. | |
void | rebuildHeap () |
Ensure that every element in this heap obeys the heap property. | |
void | sort () |
Perform an in place heap sort on the data stored in this heap. | |
boolean | isHeap () |
Do the contents of this object currently obey the heap property? | |
Protected Methods | |
int | cmp (int node1, int node2) |
Compare two Objects in this heap - wrapper around compareTo/Comparator.compare. |
|
Use given Comparator for all comparisons between elements in this Heap. Otherwise rely on compareTo methods and Comparable Objects. |
|
Ensure that every element in this heap obeys the heap property. Runs in linear time. This is meant to be called if/when the Comparator associated with this object is modified. Definition at line 187 of file Heap.java. Referenced by meapsoft.Heap.add(), meapsoft.Heap.addAll(), and meapsoft.Heap.remove(). |
|
Remove the Object o from the Heap and return true. Returns false if o is not in the Heap (as measured by o.equals()). Definition at line 116 of file Heap.java. References meapsoft.Heap.remove(). |
|
Perform an in place heap sort on the data stored in this heap. After calling sort, a call to this objects iterator() method will iterate through the data stored in the heap in ascending sorted order. This is not a stable sort. Reimplemented in meapsoft.MinHeap. |