
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
608
|
Chapter 11: Data Structures and Algorithms
The PriorityQueue<T> can be instantiated and filled with strings using code like the
Test class shown in Example 11-2.
DequeueLargest method Returns and removes the item at the tail of the queue (i.e., the last item in the queue).
DequeueSmallest
method
Returns and removes the item at the head of the queue (i.e., the first item in the queue).
PeekSmallest method Returns the item at the head of the queue (i.e., the first item in the queue).
PeekLargest method Returns the item at the tail of the queue (i.e., the last item in the queue).
GetEnumerator method Returns an enumerator that allows iteration of the items in the queue. Calls the
internalQueue method.
Example 11-2. Testing the PriorityQueue class
class Test
{
static void Main( )
{
// Create ArrayList of messages.
List<string> msgs = new List<string>( );
msgs.Add("foo");
msgs.Add("This is a longer message.");
msgs.Add("bar");
msgs.Add(@"Message with odd characters
!@#$%^&*( )_+=-0987654321~|}{[]\\;:?/>.<,");
msgs.Add(@"<
>");
msgs.Add("<text>one</text><text>two</text><text>three</text>" +
"<text>four</text>");
msgs.Add("");
msgs.Add("1234567890");
// Create a Priority Queue with the appropriate comparer.
// The comparer is created from the CompareLen type
// defined in the Discussion ...