Package dsa
Class MinPQ<Key>
- java.lang.Object
-
- dsa.MinPQ<Key>
-
-
Constructor Summary
Constructors Constructor Description MinPQ()
Constructs an empty minPQ.MinPQ(int capacity)
Constructs an empty minPQ with the given capacity.MinPQ(int capacity, Comparator<Key> c)
Constructs an empty minPQ with the given capacity and comparator.MinPQ(Comparator<Key> c)
Construct an empty minPQ with the given comparator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Key
delMin()
Removes and returns the smallest key in this minPQ.void
insert(Key key)
Addskey
to this minPQ.boolean
isEmpty()
Returnstrue
if this minPQ empty, andfalse
otherwise.Iterator<Key>
iterator()
Returns an iterator to iterate over the keys in this minPQ in ascending order.static void
main(String[] args)
Unit tests the data type.Key
min()
Returns the smallest key in this minPQ.int
size()
Returns the number of keys in this minPQ.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
-
MinPQ
public MinPQ()
Constructs an empty minPQ.
-
MinPQ
public MinPQ(Comparator<Key> c)
Construct an empty minPQ with the given comparator.- Parameters:
c
- the comparator.
-
MinPQ
public MinPQ(int capacity)
Constructs an empty minPQ with the given capacity.- Parameters:
capacity
- the capacity.
-
MinPQ
public MinPQ(int capacity, Comparator<Key> c)
Constructs an empty minPQ with the given capacity and comparator.- Parameters:
capacity
- the capacity.c
- the comparator.
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Returnstrue
if this minPQ empty, andfalse
otherwise.- Returns:
true
if this minPQ empty, andfalse
otherwise.
-
size
public int size()
Returns the number of keys in this minPQ.- Returns:
- the number of keys in this minPQ.
-
insert
public void insert(Key key)
Addskey
to this minPQ.- Parameters:
key
- the key.
-
min
public Key min()
Returns the smallest key in this minPQ.- Returns:
- the smallest key in this minPQ.
-
delMin
public Key delMin()
Removes and returns the smallest key in this minPQ.- Returns:
- the smallest key in this minPQ.
-
iterator
public Iterator<Key> iterator()
Returns an iterator to iterate over the keys in this minPQ in ascending 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.
-
-