Package dsa
Class MaxPQ<Key>
- java.lang.Object
-
- dsa.MaxPQ<Key>
-
-
Constructor Summary
Constructors Constructor Description MaxPQ()
Constructs an empty maxPQ.MaxPQ(int capacity)
Constructs an empty maxPQ with the given capacity.MaxPQ(int capacity, Comparator<Key> c)
Constructs an empty maxPQ with the given capacity and comparator.MaxPQ(Comparator<Key> c)
Construct an empty maxPQ with the given comparator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Key
delMax()
Removes and returns the largest key in this maxPQ.void
insert(Key key)
Addskey
to this maxPQ.boolean
isEmpty()
Returnstrue
if this maxPQ empty, andfalse
otherwise.Iterator<Key>
iterator()
Returns an iterator to iterate over the keys in this maxPQ in descending order.static void
main(String[] args)
Unit tests the data type.Key
max()
Returns the largest key in this maxPQ.int
size()
Returns the number of keys in this maxPQ.String
toString()
Returns a string representation of this minPQ.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
MaxPQ
public MaxPQ()
Constructs an empty maxPQ.
-
MaxPQ
public MaxPQ(int capacity)
Constructs an empty maxPQ with the given capacity.- Parameters:
capacity
- the capacity.
-
MaxPQ
public MaxPQ(Comparator<Key> c)
Construct an empty maxPQ with the given comparator.- Parameters:
c
- the comparator.
-
MaxPQ
public MaxPQ(int capacity, Comparator<Key> c)
Constructs an empty maxPQ with the given capacity and comparator.- Parameters:
capacity
- the capacity.c
- the comparator.
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Returnstrue
if this maxPQ empty, andfalse
otherwise.- Returns:
true
if this maxPQ empty, andfalse
otherwise.
-
size
public int size()
Returns the number of keys in this maxPQ.- Returns:
- the number of keys in this maxPQ.
-
insert
public void insert(Key key)
Addskey
to this maxPQ.- Parameters:
key
- the key.
-
max
public Key max()
Returns the largest key in this maxPQ.- Returns:
- the largest key in this maxPQ.
-
delMax
public Key delMax()
Removes and returns the largest key in this maxPQ.- Returns:
- the largest key in this maxPQ.
-
iterator
public Iterator<Key> iterator()
Returns an iterator to iterate over the keys in this maxPQ in descending order.
-
toString
public String toString()
Returns a string representation of this minPQ.
-
main
public static void main(String[] args)
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-
-