Source of PriorityQueueTest.java


  1: // Fig. 19.17: PriorityQueueTest.java
  2: // Standard library class PriorityQueue test program.
  3: import java.util.PriorityQueue;
  4: 
  5: public class PriorityQueueTest 
  6: {
  7:    public static void main( String args[] ) 
  8:    {
  9:       // queue of capacity 11
 10:       PriorityQueue< Double > queue = new PriorityQueue< Double >();
 11: 
 12:       // insert elements to queue
 13:       queue.offer( 3.2 );
 14:       queue.offer( 9.8 );
 15:       queue.offer( 5.4 );
 16: 
 17:       System.out.print( "Polling from queue: " );
 18: 
 19:       // display elements in queue
 20:       while ( queue.size() > 0 )
 21:       {
 22:          System.out.printf( "%.1f ", queue.peek() ); // view top element
 23:          queue.poll(); // remove top element
 24:       } // end while
 25:    } // end main
 26: } // end class PriorityQueueTest
 27: 
 28: /**************************************************************************
 29:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 30:  * Pearson Education, Inc. All Rights Reserved.                           *
 31:  *                                                                        *
 32:  * DISCLAIMER: The authors and publisher of this book have used their     *
 33:  * best efforts in preparing the book. These efforts include the          *
 34:  * development, research, and testing of the theories and programs        *
 35:  * to determine their effectiveness. The authors and publisher make       *
 36:  * no warranty of any kind, expressed or implied, with regard to these    *
 37:  * programs or to the documentation contained in these books. The authors *
 38:  * and publisher shall not be liable in any event for incidental or       *
 39:  * consequential damages in connection with, or arising out of, the       *
 40:  * furnishing, performance, or use of these programs.                     *
 41:  *************************************************************************/