Click or drag to resize
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.

Inheritance Hierarchy
SystemObject
  Algs4NetIndexMinPQKey

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class IndexMinPQ<Key> : IEnumerable<int>, 
	IEnumerable
where Key : Object, IComparable<Key>

Type Parameters

Key

The IndexMinPQKey type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyCount
Returns the number of keys on this priority queue.
Public propertyIsEmpty
Returns true if this priority queue is empty.
Public propertyMinIndex
Returns an index associated with a minimum key.
Public propertyMinKey
Returns the current minimum key.
Top
Methods
  NameDescription
Public methodChange
Change the key associated with index i to the specified value.
Public methodChangeKey
Change the key associated with index i to the specified value.
Public methodContains
Is i an index on this priority queue?
Public methodDecreaseKey
Decrease the key associated with index i to the specified value.
Public methodDelete
Remove the key associated with index i.
Public methodDelMin
Removes a minimum key and returns its associated index.
Public methodGetEnumerator
Returns an iterator that iterates over the keys on this priority queue in ascending order.
Public methodIncreaseKey
Increase the key associated with index i to the specified value.
Public methodInsert
Associates key with index i.
Public methodKeyOf
Returns the key associated with index i.
Public methodStatic memberMainTest
Demo test the IndexMinPQ data type.
Public methodToString
Formatted string for the IndexMinPQ class
(Overrides ObjectToString.)
Top
Remarks
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 IndexMinPQ implementation by Robert Sedgewick and Kevin Wayne.

See Also