Package dsa
Class IndexMinPQ<Key extends Comparable<Key>>
- java.lang.Object
-
- dsa.IndexMinPQ<Key>
-
-
Constructor Summary
Constructors Constructor Description IndexMinPQ(int maxN)
Constructs an empty indexMinPQ with indices from the interval[0, maxN)
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
change(int i, Key key)
Changes the key associated with indexi
tokey
.boolean
contains(int i)
Returnstrue
ifi
is an index in this indexMinPQ, andfalse
otherwise.void
delete(int i)
Removes the key associated with indexi
in this indexMinPQ.int
delMin()
Removes the smallest key from this indexMinPQ and returns its associated index.void
insert(int i, Key key)
Associateskey
with indexi
in this indexMinPQ.boolean
isEmpty()
Returnstrue
if this indexMinPQ empty, andfalse
otherwise.Iterator<Integer>
iterator()
Returns an iterator to iterate over the indices in this indexMinPQ in ascending order of the associated keys.Key
keyOf(int i)
Returns the key associated with indexi
in this indexMinPQ.static void
main(String[] args)
Unit tests the data type.int
minIndex()
Returns the index associated with the smallest key in this indexMinPQ.Key
minKey()
Returns the smallest key in this indexMinPQ.int
size()
Returns the number of keys in this indexMinPQ.String
toString()
Returns a string representation of this indexMinPQ.-
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
-
-
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Returnstrue
if this indexMinPQ empty, andfalse
otherwise.- Returns:
true
if this indexMinPQ empty, andfalse
otherwise.
-
size
public int size()
Returns the number of keys in this indexMinPQ.- Returns:
- the number of keys in this indexMinPQ.
-
insert
public void insert(int i, Key key)
Associateskey
with indexi
in this indexMinPQ.- Parameters:
i
- the index.key
- the key.
-
change
public void change(int i, Key key)
Changes the key associated with indexi
tokey
.- Parameters:
i
- the index.key
- the key.
-
contains
public boolean contains(int i)
Returnstrue
ifi
is an index in this indexMinPQ, andfalse
otherwise.- Parameters:
i
- an index.- Returns:
true
ifi
is an index in this indexMinPQ, andfalse
otherwise.
-
minIndex
public int minIndex()
Returns the index associated with the smallest key in this indexMinPQ.- Returns:
- the index associated with the smallest key in this indexMinPQ.
-
minKey
public Key minKey()
Returns the smallest key in this indexMinPQ.- Returns:
- the smallest key in this indexMinPQ.
-
keyOf
public Key keyOf(int i)
Returns the key associated with indexi
in this indexMinPQ.- Parameters:
i
- the index.- Returns:
- the key associated with index
i
in this indexMinPQ.
-
delMin
public int delMin()
Removes the smallest key from this indexMinPQ and returns its associated index.- Returns:
- the index associated with the smallest key in this indexMinPQ.
-
delete
public void delete(int i)
Removes the key associated with indexi
in this indexMinPQ.- Parameters:
i
- the index.
-
iterator
public Iterator<Integer> iterator()
Returns an iterator to iterate over the indices in this indexMinPQ in ascending order of the associated keys.- Specified by:
iterator
in interfaceIterable<Key extends Comparable<Key>>
- Returns:
- an iterator to iterate over the indices in this indexMinPQ in ascending order of the associated keys.
-
toString
public String toString()
Returns a string representation of this indexMinPQ.
-
main
public static void main(String[] args)
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-
-