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.
Namespace: Algs4Net
public class MaxPQ<Key> : IEnumerable<Key>, IEnumerable where Key : Object, IComparable<Key>
The MaxPQKey type exposes the following members.
Name | Description | |
---|---|---|
![]() | MaxPQKey |
Initializes an empty priority queue. |
![]() | MaxPQKey(ComparerKey) |
Initializes an empty priority queue using the given comparator. |
![]() | MaxPQKey(Int32) |
Initializes an empty priority queue with the given initial capacity. |
![]() | MaxPQKey(Key) |
Initializes a priority queue from the array of keys.
Takes time proportional to the number of keys, using sink-based heap construction. |
![]() | MaxPQKey(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. |
![]() | Max |
Returns a smallest key on this priority queue. |
Name | Description | |
---|---|---|
![]() | DelMax |
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 MaxPQ data type. |
![]() | ToString |
Formatted string for the MaxPQ class
(Overrides ObjectToString.) |
This class is a C# port from the original Java class MaxPQ implementation by Robert Sedgewick and Kevin Wayne.