Click or drag to resize
MinPQKey Class

The MinPQ class represents a priority queue of generic keys. It supports the usual Insert and Delete-the-minimum operations, along with 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. The Insert and Delete-the-minimum operations take logarithmic amortized time. The Min, 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
  Algs4NetMinPQKey

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

Type Parameters

Key

The MinPQKey type exposes the following members.

Constructors
  NameDescription
Public methodMinPQKey
Initializes an empty priority queue.
Public methodMinPQKey(ComparerKey)
Initializes an empty priority queue using the given comparator.
Public methodMinPQKey(Int32)
Initializes an empty priority queue with the given initial capacity.
Public methodMinPQKey(Key)
Initializes a priority queue from the array of keys. Takes time proportional to the number of keys, using sink-based heap construction.
Public methodMinPQKey(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 propertyMin
Returns a smallest key on this priority queue.
Top
Methods
  NameDescription
Public methodDelMin
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 MinPQ data type.
Public methodToString
Formatted string for the MinPQ 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 MinPQ implementation by Robert Sedgewick and Kevin Wayne.

See Also