Package algs24
Class MyMinMaxPQ<K extends Comparable<? super K>>
java.lang.Object
algs24.MyMinMaxPQ<K>
- All Implemented Interfaces:
Iterable<K>
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaExch(int ai, int aj) private booleanaGreater(int i, int j) private voidaSink(int k) private static booleanprivate voidaSwim(int k) private voidbExch(int bi, int bj) private booleanbLess(int i, int j) private voidbSink(int k) private voidbSwim(int k) private voidcheck()delMax()Delete and return the largest key on the priority queue.delMin()Delete and return the smallest key on the priority queue.voidAdd a new key to the priority queue.booleanisEmpty()Is the priority queue empty?booleanisFull()Is the priority queue full?private booleanisMaxHeap(int k) private booleanisMinHeap(int k) private booleaniterator()Return an iterator that iterates over all of the keys on the priority queue in ascending order.static voidmin()Return the smallest key on the priority queue.private static voidrandomEmpty(MyMinMaxPQ<Integer> pq, boolean log) private static voidrandomOps(MyMinMaxPQ<Integer> pq, int NUMOPS, boolean log) private static MyMinMaxPQ<Integer> randomPQ(int maxSize) private static intA test client.private voidshowHeap()intsize()Return the number of items on the priority queue.private voidswap(int[] a, int i, int j) private voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
N
-
MAXN
-
a
-
b
-
ab
-
ba
-
-
Constructor Details
-
MyMinMaxPQ
-
-
Method Details
-
isEmpty
Is the priority queue empty? -
isFull
Is the priority queue full? -
size
Return the number of items on the priority queue. -
min
Return the smallest key on the priority queue. Throw an exception if the priority queue is empty. -
insert
Add a new key to the priority queue. -
delMin
Delete and return the smallest key on the priority queue. Throw an exception if the priority queue is empty. -
delMax
Delete and return the largest key on the priority queue. Throw an exception if the priority queue is empty. -
aSwim
-
aSink
-
bSwim
-
bSink
-
aGreater
-
bLess
-
swap
-
swap
-
aExch
-
bExch
-
showHeap
-
check
-
isMinMaxHeap
-
isMaxHeap
-
isMinHeap
-
iterator
Return an iterator that iterates over all of the keys on the priority queue in ascending order.The iterator doesn't implement
remove()since it's optional.- Specified by:
iteratorin interfaceIterable<K extends Comparable<? super K>>
-
randomValue
A test client. -
randomPQ
-
randomOps
-
randomEmpty
-
assertionsAreOn
-
main
-