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.
|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.|
|Ensure that every element in this heap obeys the heap property. |
|Perform an in place heap sort on the data stored in this heap. |
|Do the contents of this object currently obey the heap property?|
|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.
Remove the Object o from the Heap and return true.
Returns false if o is not in the Heap (as measured by o.equals()).
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.