// PriorityQueueTest.java
// Standard library class PriorityQueue test program.
package chapter36;

import java.util.PriorityQueue;

public class PriorityQueueTest
{
    public static void main( String args[] )
    {
        // Create a PriorityQueue that stores Doubles
        // with an initial capacity of 11 elements (default initial capacity)
        // and orders the elements according to the object’s natural ordering
        PriorityQueue< Double > queue = new PriorityQueue< Double >();

        // Use method offer to add elements to the priority queue
        queue.offer( 3.2 );
        queue.offer( 9.8 );
        queue.offer( 5.4 );

        System.out.print( "Polling from queue: " );

        // display elements in queue
        // Use method size to determine whether the priority queue is empty
        while ( queue.size() > 0 )
        {
            // Use method peek to retrieve the highest-priority element in the queue
            System.out.printf( "%.1f ", queue.peek() );  // view top element
            // Use method pool to remove the highest-priority element from the queue
            queue.poll(); // remove top element
        } // end while
    } // end main
} // end class PriorityQueueTest

