public class BinaryHeap<T extends BinaryHeap.Node>
extends java.lang.Object
BinaryHeap.Node
class can be extended to store additional information.Modifier and Type | Class and Description |
---|---|
static class |
BinaryHeap.Node
A binary heap node.
|
Modifier and Type | Field and Description |
---|---|
int |
size |
Constructor and Description |
---|
BinaryHeap() |
BinaryHeap(int capacity,
boolean isMaxHeap) |
Modifier and Type | Method and Description |
---|---|
T |
add(T node)
Adds the node to the heap using its current value.
|
T |
add(T node,
double value)
Sets the node's value and adds it to the heap.
|
void |
clear() |
boolean |
contains(T node,
boolean identity)
Returns true if the heap contains the specified node.
|
boolean |
equals(java.lang.Object obj) |
int |
hashCode() |
boolean |
isEmpty()
Returns true if the heap is empty.
|
boolean |
notEmpty()
Returns true if the heap has one or more items.
|
T |
peek()
Returns the first item in the heap.
|
T |
pop()
Removes the first item in the heap and returns it.
|
T |
remove(T node) |
void |
setValue(T node,
double value)
Changes the value of the node, which should already be in the heap.
|
java.lang.String |
toString() |
public BinaryHeap()
public BinaryHeap(int capacity, boolean isMaxHeap)
public T add(T node)
public T add(T node, double value)
public boolean contains(T node, boolean identity)
identity
- If true, == comparison will be used. If false, .equals() comparison will be used.public T peek()
public T pop()
public boolean notEmpty()
public boolean isEmpty()
public void clear()
public void setValue(T node, double value)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © Eben Howard 2012–2022. All rights reserved.