public class BinaryHeap<T extends BinaryHeap.Node> extends 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,
float 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(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,
float value)
Changes the value of the node, which should already be in the heap.
|
String |
toString() |
public BinaryHeap()
public BinaryHeap(int capacity, boolean isMaxHeap)
public T add(T node)
public T add(T node, float 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, float value)
Copyright © 2019. All rights reserved.