// Copyright (c) 1996, 1997, 1998 Bruno R. Preiss, P.Eng. // $Author: brpreiss $ // $Date: 1998/12/14 02:52:01 $ // $RCSfile: Demo6.java,v $ // $Revision: 3.4 $ package Opus5; /** * Demonstration program that tests the following classes: * BinaryHeap, * LeftistHeap, * BinomialQueue, and * Deap. * @see BinaryHeap * @see LeftistHeap * @see BinomialQueue * @see Deap * @author Bruno R. Preiss, P.Eng. * @version $Id: Demo6.java,v 3.4 1998/12/14 02:52:01 brpreiss Exp $ **/ public class Demo6 { //[ final String copyright = "@(#) Copyright (c) 1998 by Bruno R. Preiss, P.Eng."; //] /** * Performs various tests on the specified priority queue. * @param pqueue The priority queue to be tested. **/ private static void testPriorityQueue (PriorityQueue pqueue) { Terminal.out.println (pqueue); pqueue.enqueue (new Int (3)); pqueue.enqueue (new Int (1)); pqueue.enqueue (new Int (4)); pqueue.enqueue (new Int (1)); pqueue.enqueue (new Int (5)); pqueue.enqueue (new Int (9)); pqueue.enqueue (new Int (2)); pqueue.enqueue (new Int (6)); pqueue.enqueue (new Int (5)); pqueue.enqueue (new Int (4)); Terminal.out.println (pqueue); while (!pqueue.isEmpty ()) { Comparable obj = pqueue.dequeueMin (); Terminal.out.println (obj); } } /** * Performs various tests on the specified double-ended priority queue. * @param pqueue The double-ended priority queue to be tested. **/ private static void testDoubleEndedPriorityQueue ( DoubleEndedPriorityQueue pqueue) { testPriorityQueue (pqueue); Terminal.out.println (pqueue); pqueue.enqueue (new Int (3)); pqueue.enqueue (new Int (1)); pqueue.enqueue (new Int (4)); pqueue.enqueue (new Int (1)); pqueue.enqueue (new Int (5)); pqueue.enqueue (new Int (9)); pqueue.enqueue (new Int (2)); pqueue.enqueue (new Int (6)); pqueue.enqueue (new Int (5)); pqueue.enqueue (new Int (4)); Terminal.out.println (pqueue); while (!pqueue.isEmpty ()) { Comparable obj = pqueue.dequeueMax (); Terminal.out.println (obj); } } /** * The (static) main program. * Invokes various test routines. * @param args The command-line arguments. Ignored. **/ public static void main (String[] args) { PriorityQueue pqueue = new BinaryHeap (256); testPriorityQueue (pqueue); pqueue = new LeftistHeap (); testPriorityQueue (pqueue); pqueue = new BinomialQueue (); testPriorityQueue (pqueue); DoubleEndedPriorityQueue depqueue = new Deap (256); testDoubleEndedPriorityQueue (depqueue); } }