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.
Namespace: Algs4Net
public class MinPQ<Key> : IEnumerable<Key>, IEnumerable where Key : Object, IComparable<Key>
The MinPQKey type exposes the following members.
Name | Description | |
---|---|---|
![]() | MinPQKey |
Initializes an empty priority queue. |
![]() | MinPQKey(ComparerKey) |
Initializes an empty priority queue using the given comparator. |
![]() | MinPQKey(Int32) |
Initializes an empty priority queue with the given initial capacity. |
![]() | MinPQKey(Key) |
Initializes a priority queue from the array of keys.
Takes time proportional to the number of keys, using sink-based heap construction. |
![]() | MinPQKey(Int32, ComparerKey) |
Initializes an empty priority queue with the given initial capacity,
using the given comparator. |
Name | Description | |
---|---|---|
![]() | Count |
Returns the number of keys on this priority queue. |
![]() | IsEmpty |
Returns true if this priority queue is empty. |
![]() | Min |
Returns a smallest key on this priority queue. |
Name | Description | |
---|---|---|
![]() | DelMin |
Removes and returns a smallest key on this priority queue. |
![]() | GetEnumerator |
Returns an iterator that iterates over the keys on this priority queue
in ascending order. |
![]() | Insert |
Adds a new key to this priority queue. |
![]() ![]() | MainTest |
Demo test the MinPQ data type. |
![]() | ToString |
Formatted string for the MinPQ class
(Overrides ObjectToString.) |
This class is a C# port from the original Java class MinPQ implementation by Robert Sedgewick and Kevin Wayne.