Exemplo n.º 1
0
  public static void main(String[] args) {
    PriorityQueue<Integer> priorityQueue = new PriorityQueue<Integer>();
    Random rand = new Random(47);

    for (int i = 0; i < 10; i++) {
      priorityQueue.offer(rand.nextInt(i + 10));
    }

    QueueDemo.printQueue(priorityQueue);

    List<Integer> ints = Arrays.asList(25, 22, 20, 18, 14, 9, 3, 1, 1, 2, 3, 9, 14, 18, 21, 23, 25);
    priorityQueue = new PriorityQueue<Integer>(ints);
    QueueDemo.printQueue(priorityQueue);
    priorityQueue = new PriorityQueue<Integer>(ints.size(), Collections.reverseOrder());
    priorityQueue.addAll(ints);
    QueueDemo.printQueue(priorityQueue);

    String fact = "EDUCATION SHOULD ESCHEW OBFUSCATION";
    List<String> strings = Arrays.asList(fact.split(""));
    PriorityQueue<String> stringPQ = new PriorityQueue<String>(strings);
    QueueDemo.printQueue(stringPQ);
  }