FileDocCategorySizeDatePackage
PriorityQueueTester.javaAPI DocExample759Sat May 22 08:34:26 BST 2004com.oreilly.tiger.ch01

PriorityQueueTester

public class PriorityQueueTester extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


    PriorityQueue<Integer> pq =
      new PriorityQueue<Integer>(20, 
        new Comparator<Integer>() {
          public int compare(Integer i, Integer j) {
            int result = i%2 - j%2;
            if (result == 0)
              result = i-j;
            return result;
          }
        }
      );

    // Fill up with data, in an odd order
    for (int i=0; i<20; i++) {
      pq.offer(20-i);
    }

    // Print out and check ordering
    for (int i=0; i<20; i++) {
      System.out.println(pq.poll());
    }