类 MultiwayMinPQ<Key>
- java.lang.Object
-
- edu.princeton.cs.algs4.MultiwayMinPQ<Key>
-
- 所有已实现的接口:
java.lang.Iterable<Key>
public class MultiwayMinPQ<Key> extends java.lang.Object implements java.lang.Iterable<Key>
The MultiwayMinPQ class represents a priority queue of generic keys. It supports the usual insert and delete-the-minimum operations. It also supports methods for peeking at the minimum key, testing if the priority queue is empty, and iterating through the keys. It is possible to build the priority queue using a Comparator. If not, the natural order relation between the keys will be used. This implementation uses a multiway heap. For simplified notations, logarithm in base d will be referred as log-d The delete-the-minimum operation takes time proportional to d*log-d(n) The insert takes time proportional to log-d(n) The is-empty, min-key and size operations take constant time. Constructor takes time proportional to the specified capacity.
-
-
构造器概要
构造器 构造器 说明 MultiwayMinPQ(int d)
Initializes an empty priority queue Worst case is O(d)MultiwayMinPQ(java.util.Comparator<Key> comparator, int d)
Initializes an empty priority queue Worst case is O(d)MultiwayMinPQ(java.util.Comparator<Key> comparator, Key[] a, int d)
Initializes a priority queue with given indexes Worst case is O(a*log-d(n))MultiwayMinPQ(Key[] a, int d)
Initializes a priority queue with given indexes Worst case is O(n*log-d(n))
-
方法概要
修饰符和类型 方法 说明 Key
delMin()
Deletes the minimum key Worst case is O(d*log-d(n))void
insert(Key key)
Puts a Key on the priority queue Worst case is O(log-d(n))boolean
isEmpty()
Whether the priority queue is empty Worst case is O(1)java.util.Iterator<Key>
iterator()
Gets an Iterator over the keys in the priority queue in ascending order The Iterator does not implement the remove() method iterator() : Worst case is O(n) next() : Worst case is O(d*log-d(n)) hasNext() : Worst case is O(1)Key
minKey()
Gets the minimum key currently in the queue Worst case is O(1)int
size()
Number of elements currently on the priority queue Worst case is O(1)
-
-
-
构造器详细资料
-
MultiwayMinPQ
public MultiwayMinPQ(int d)
Initializes an empty priority queue Worst case is O(d)- 参数:
d
- dimension of the heap- 抛出:
java.lang.IllegalArgumentException
- ifd < 2
-
MultiwayMinPQ
public MultiwayMinPQ(java.util.Comparator<Key> comparator, int d)
Initializes an empty priority queue Worst case is O(d)- 参数:
d
- dimension of the heapcomparator
- a Comparator over the keys- 抛出:
java.lang.IllegalArgumentException
- ifd < 2
-
MultiwayMinPQ
public MultiwayMinPQ(Key[] a, int d)
Initializes a priority queue with given indexes Worst case is O(n*log-d(n))- 参数:
d
- dimension of the heapa
- an array of keys- 抛出:
java.lang.IllegalArgumentException
- ifd < 2
-
MultiwayMinPQ
public MultiwayMinPQ(java.util.Comparator<Key> comparator, Key[] a, int d)
Initializes a priority queue with given indexes Worst case is O(a*log-d(n))- 参数:
d
- dimension of the heapcomparator
- a Comparator over the keysa
- an array of keys- 抛出:
java.lang.IllegalArgumentException
- ifd < 2
-
-
方法详细资料
-
isEmpty
public boolean isEmpty()
Whether the priority queue is empty Worst case is O(1)- 返回:
- true if the priority queue is empty, false if not
-
size
public int size()
Number of elements currently on the priority queue Worst case is O(1)- 返回:
- the number of elements on the priority queue
-
insert
public void insert(Key key)
Puts a Key on the priority queue Worst case is O(log-d(n))- 参数:
key
- a Key
-
minKey
public Key minKey()
Gets the minimum key currently in the queue Worst case is O(1)- 返回:
- the minimum key currently in the priority queue
- 抛出:
java.util.NoSuchElementException
- if the priority queue is empty
-
delMin
public Key delMin()
Deletes the minimum key Worst case is O(d*log-d(n))- 返回:
- the minimum key
- 抛出:
java.util.NoSuchElementException
- if the priority queue is empty
-
iterator
public java.util.Iterator<Key> iterator()
Gets an Iterator over the keys in the priority queue in ascending order The Iterator does not implement the remove() method iterator() : Worst case is O(n) next() : Worst case is O(d*log-d(n)) hasNext() : Worst case is O(1)- 指定者:
iterator
在接口中java.lang.Iterable<Key>
- 返回:
- an Iterator over the keys in the priority queue in ascending order
-
-