Click or drag to resize
MaxPQKey Class

The MaxPQ class represents a priority queue of generic keys. It supports the usual Insert and Delete-the-maximum operations, along with methods for peeking at the maximum key, testing if the priority queue is empty, and iterating through the keys.

This implementation uses a binary heap. The Insert and Delete-the-maximum operations take logarithmic amortized time. The Max, Count, and IsEmpty operations take constant time. Construction takes time proportional to the specified capacity or the number of items used to initialize the data structure.

Inheritance Hierarchy
SystemObject
  Algs4NetMaxPQKey

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

Type Parameters

Key

The MaxPQKey type exposes the following members.

Constructors
  NameDescription
Public methodMaxPQKey
Initializes an empty priority queue.
Public methodMaxPQKey(ComparerKey)
Initializes an empty priority queue using the given comparator.
Public methodMaxPQKey(Int32)
Initializes an empty priority queue with the given initial capacity.
Public methodMaxPQKey(Key)
Initializes a priority queue from the array of keys. Takes time proportional to the number of keys, using sink-based heap construction.
Public methodMaxPQKey(Int32, ComparerKey)
Initializes an empty priority queue with the given initial capacity, using the given comparator.
Top
Properties
  NameDescription
Public propertyCount
Returns the number of keys on this priority queue.
Public propertyIsEmpty
Returns true if this priority queue is empty.
Public propertyMax
Returns a smallest key on this priority queue.
Top
Methods
  NameDescription
Public methodDelMax
Removes and returns a smallest key on this priority queue.
Public methodGetEnumerator
Returns an iterator that iterates over the keys on this priority queue in ascending order.
Public methodInsert
Adds a new key to this priority queue.
Public methodStatic memberMainTest
Demo test the MaxPQ data type.
Public methodToString
Formatted string for the MaxPQ 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 MaxPQ implementation by Robert Sedgewick and Kevin Wayne.

See Also