Node class can be extended to store additional information.
| Modifier and Type | Class and Description |
|---|---|
| public static class | BinaryHeap.
A binary heap node. |
| Modifier and Type | Field and Description |
|---|---|
| private final boolean | |
| private BinaryHeap. | |
| public int |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public T | |
| public T | |
| public void | |
| public boolean | contains(T node, boolean
If true, == comparison will be used. If false, .equals() comparison will be used. identity)Returns true if the heap contains the specified node. |
| private void | |
| public boolean | equals(Object obj)
Overrides java. Indicates whether some other object is "equal to" this one. |
| public int | |
| public boolean | |
| public boolean | |
| public T | |
| public T | |
| public T | |
| public void | |
| public String | |
| private void |
| isMaxHeap | back to summary |
|---|---|
| private final boolean isMaxHeap | |
| nodes | back to summary |
|---|---|
| private BinaryHeap. | |
| size | back to summary |
|---|---|
| public int size | |
| BinaryHeap | back to summary |
|---|---|
| public BinaryHeap() | |
| BinaryHeap | back to summary |
|---|---|
| public BinaryHeap(int capacity, boolean isMaxHeap) | |
| add | back to summary |
|---|---|
| public T add(T node) Adds the node to the heap using its current value. The node should not already be in the heap.
| |
| add | back to summary |
|---|---|
| public T add(T node, float value) Sets the node's value and adds it to the heap. The node should not already be in the heap.
| |
| clear | back to summary |
|---|---|
| public void clear() | |
| contains | back to summary |
|---|---|
| public boolean contains(T node, boolean identity) Returns true if the heap contains the specified node.
| |
| down | back to summary |
|---|---|
| private void down(int index) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Returns true if the heap is empty. | |
| notEmpty | back to summary |
|---|---|
| public boolean notEmpty() Returns true if the heap has one or more items. | |
| peek | back to summary |
|---|---|
| public T peek() Returns the first item in the heap. This is the item with the lowest value (or highest value if this heap is configured as a max heap). | |
| pop | back to summary |
|---|---|
| public T pop() Removes the first item in the heap and returns it. This is the item with the lowest value (or highest value if this heap is configured as a max heap). | |
| remove | back to summary |
|---|---|
public T remove(T node)
| |
| setValue | back to summary |
|---|---|
| public void setValue(T node, float value) Changes the value of the node, which should already be in the heap. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| up | back to summary |
|---|---|
| private void up(int index) | |
| Access | Constructor and Description |
|---|---|
| public | Node(float
The initial value for the node. To change the value, use value)BinaryHeap#add(Node, float) if the node is
not in the heap, or BinaryHeap#setValue(Node, float) if the node is in the heap.
|
| Modifier and Type | Method and Description |
|---|---|
| public float | |
| public String |
| Node | back to summary |
|---|---|
public Node(float value)
| |
| getValue | back to summary |
|---|---|
| public float getValue() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |