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

Inheritance Hierarchy
SystemObject
  Algs4NetIndexMaxPQKey

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

Type Parameters

Key

The IndexMaxPQKey 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 propertyMaxIndex
Returns an index associated with a maximum key.
Public propertyMaxKey
Returns a maximum key.
Top
Methods
  NameDescription
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 on the priority queue associated with index i.
Public methodDelMax
Removes a maximum key and returns its associated index.
Public methodGetEnumerator
Returns an iterator that iterates over the keys on the priority queue in descending order.
Public methodIncreaseKey
Increase the key associated with index i to the specified value.
Public methodInsert
Associate key with index i.
Public methodKeyOf
Returns the key associated with index i.
Public methodStatic memberMainTest
Demo test the IndexMaxPQ data type.
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 IndexMaxPQ implementation by the respective authors.

See Also