Package algs24
Class MyMinMaxPQ<K extends Comparable<? super K>>
java.lang.Object
algs24.MyMinMaxPQ<K>
- All Implemented Interfaces:
Iterable<K>
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate void
aExch
(int ai, int aj) private boolean
aGreater
(int i, int j) private void
aSink
(int k) private static boolean
private void
aSwim
(int k) private void
bExch
(int bi, int bj) private boolean
bLess
(int i, int j) private void
bSink
(int k) private void
bSwim
(int k) private void
check()
delMax()
Delete and return the largest key on the priority queue.delMin()
Delete and return the smallest key on the priority queue.void
Add a new key to the priority queue.boolean
isEmpty()
Is the priority queue empty?boolean
isFull()
Is the priority queue full?private boolean
isMaxHeap
(int k) private boolean
isMinHeap
(int k) private boolean
iterator()
Return an iterator that iterates over all of the keys on the priority queue in ascending order.static void
min()
Return the smallest key on the priority queue.private static void
randomEmpty
(MyMinMaxPQ<Integer> pq, boolean log) private static void
randomOps
(MyMinMaxPQ<Integer> pq, int NUMOPS, boolean log) private static MyMinMaxPQ
<Integer> randomPQ
(int maxSize) private static int
A test client.private void
showHeap()
int
size()
Return the number of items on the priority queue.private void
swap
(int[] a, int i, int j) private void
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:
iterator
in interfaceIterable<K extends Comparable<? super K>>
-
randomValue
A test client. -
randomPQ
-
randomOps
-
randomEmpty
-
assertionsAreOn
-
main
-