|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectweiss.nonstandard.BinaryHeap<AnyType>
public class BinaryHeap<AnyType extends java.lang.Comparable<? super AnyType>>
Implements a binary heap. Note that all "matching" is based on the compareTo method.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface weiss.nonstandard.PriorityQueue |
---|
PriorityQueue.Position<AnyType> |
Constructor Summary | |
---|---|
BinaryHeap()
Construct the binary heap. |
|
BinaryHeap(AnyType[] items)
Construct the binary heap from an array. |
Method Summary | |
---|---|
void |
decreaseKey(PriorityQueue.Position<AnyType> p,
AnyType newVal)
Change the value of the item stored in the pairing heap. |
AnyType |
deleteMin()
Remove the smallest item from the priority queue. |
AnyType |
findMin()
Find the smallest item in the priority queue. |
PriorityQueue.Position<AnyType> |
insert(AnyType x)
Insert into the priority queue. |
boolean |
isEmpty()
Test if the priority queue is logically empty. |
static void |
main(java.lang.String[] args)
|
void |
makeEmpty()
Make the priority queue logically empty. |
int |
size()
Returns size. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BinaryHeap()
public BinaryHeap(AnyType[] items)
items
- the inital items in the binary heap.Method Detail |
---|
public PriorityQueue.Position<AnyType> insert(AnyType x)
insert
in interface PriorityQueue<AnyType extends java.lang.Comparable<? super AnyType>>
x
- the item to insert.
public void decreaseKey(PriorityQueue.Position<AnyType> p, AnyType newVal)
PriorityQueue
decreaseKey
in interface PriorityQueue<AnyType extends java.lang.Comparable<? super AnyType>>
p
- any non-null Position returned by insert.newVal
- the new value, which must be smaller
than the currently stored value.
java.lang.UnsupportedOperationException
- because no Positions are returned
by the insert method for BinaryHeap.public AnyType findMin()
findMin
in interface PriorityQueue<AnyType extends java.lang.Comparable<? super AnyType>>
UnderflowException
- if empty.public AnyType deleteMin()
deleteMin
in interface PriorityQueue<AnyType extends java.lang.Comparable<? super AnyType>>
UnderflowException
- if empty.public boolean isEmpty()
isEmpty
in interface PriorityQueue<AnyType extends java.lang.Comparable<? super AnyType>>
public int size()
size
in interface PriorityQueue<AnyType extends java.lang.Comparable<? super AnyType>>
public void makeEmpty()
makeEmpty
in interface PriorityQueue<AnyType extends java.lang.Comparable<? super AnyType>>
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |