IndexMaxPQKey Class |
The IndexMaxPQ class represents an indexed priority queue of generic keys. It supports the usual Insert and Delete-the-maximum operations, along with Delete and Change-the-key methods. In order to let the client refer to items on the priority queue, an integer between 0 and maxN-1 is associated with each key. The client uses this integer to specify which key to delete or change. It also supports methods for peeking at a maximum key, testing if the priority queue is empty, and iterating through the keys.
This implementation uses a binary heap along with an array to associate keys with integers in the given range. The Insert, Delete-the-maximum, Delete, Change-key, Decrease-key, and Increase-key operations take logarithmic time. The IsEmpty, Count, Max-index, Max-key, and Key-of operations take constant time. Construction takes time proportional to the specified capacity.
Namespace: Algs4Net
public class IndexMaxPQ<Key> : IEnumerable<int>, IEnumerable where Key : Object, IComparable<Key>
The IndexMaxPQKey type exposes the following members.
Name | Description | |
---|---|---|
![]() | IndexMaxPQKey |
Initializes an empty indexed priority queue with indices between 0
and maxN - 1. |
Name | Description | |
---|---|---|
![]() | Count |
Returns the number of keys on this priority queue. |
![]() | IsEmpty |
Returns true if this priority queue is empty. |
![]() | MaxIndex |
Returns an index associated with a maximum key. |
![]() | MaxKey |
Returns a maximum key. |
Name | Description | |
---|---|---|
![]() | ChangeKey |
Change the key associated with index i to the specified value. |
![]() | Contains |
Is i an index on this priority queue? |
![]() | DecreaseKey |
Decrease the key associated with index i to the specified value. |
![]() | Delete |
Remove the key on the priority queue associated with index i. |
![]() | DelMax |
Removes a maximum key and returns its associated index. |
![]() | GetEnumerator |
Returns an iterator that iterates over the keys on the
priority queue in descending order. |
![]() | IncreaseKey |
Increase the key associated with index i to the specified value. |
![]() | Insert |
Associate key with index i. |
![]() | KeyOf |
Returns the key associated with index i. |
![]() ![]() | MainTest |
Demo test the IndexMaxPQ data type. |
For additional documentation, see Section 2.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
This class is a C# port from the original Java class IndexMaxPQ implementation by the respective authors.