IndexMinPQKey Class |
The IndexMinPQ class represents an indexed priority queue of generic keys. It supports the usual Insert and Delete-the-minimum operations, along with Delete and Change-the-key methods. In order to let the client refer to keys 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 the minimum 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-minimum, Delete, Change-key, Decrease-key, and Increase-key operations take logarithmic time. The Is-empty, Count, Min-index, Min-key, and Key-of operations take constant time. Construction takes time proportional to the specified capacity.
Namespace: Algs4Net
public class IndexMinPQ<Key> : IEnumerable<int>, IEnumerable where Key : Object, IComparable<Key>
The IndexMinPQKey type exposes the following members.
Name | Description | |
---|---|---|
![]() | IndexMinPQKey | 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. |
![]() | MinIndex |
Returns an index associated with a minimum key. |
![]() | MinKey | Returns the current minimum key. |
Name | Description | |
---|---|---|
![]() | Change |
Change the key associated with index i to the specified value. |
![]() | 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 associated with index i. |
![]() | DelMin |
Removes a minimum key and returns its associated index. |
![]() | GetEnumerator |
Returns an iterator that iterates over the keys on this priority queue
in ascending order. |
![]() | IncreaseKey |
Increase the key associated with index i to the specified value. |
![]() | Insert | Associates key with index i. |
![]() | KeyOf |
Returns the key associated with index i. |
![]() ![]() | MainTest |
Demo test the IndexMinPQ data type. |
![]() | ToString |
Formatted string for the IndexMinPQ class
(Overrides ObjectToString.) |
This class is a C# port from the original Java class IndexMinPQ implementation by Robert Sedgewick and Kevin Wayne.