Example usage for java.util PriorityQueue PriorityQueue

List of usage examples for java.util PriorityQueue PriorityQueue

Introduction

In this page you can find the example usage for java.util PriorityQueue PriorityQueue.

Prototype

public PriorityQueue(SortedSet<? extends E> c) 

Source Link

Document

Creates a PriorityQueue containing the elements in the specified sorted set.

Usage

From source file:Main.java

public static void main(String args[]) {

    PriorityQueue<Integer> prq = new PriorityQueue<Integer>(100);

    for (int i = 0; i < 10; i++) {
        prq.add(i);//  w w  w.  j a v a2  s  .  c  o  m
    }
    System.out.println(prq);
}

From source file:Main.java

public static void main(String args[]) {

    SortedSet<String> set = new TreeSet<String>();

    PriorityQueue<String> p = new PriorityQueue<String>(set);

    System.out.println(p);//from   www . j av a2 s.  co  m
}

From source file:Main.java

public static void main(String args[]) {

    Collection<String> c = new ArrayList<String>();

    PriorityQueue<String> p = new PriorityQueue<String>(c);

    System.out.println(p);/*from  ww  w  . j ava 2  s.  c  o m*/
}

From source file:ProductQuality.java

public static void main(String args[]) {

    PriorityQueue<Product> pq = new PriorityQueue<Product>(3);

    pq.add(new Product("A", ProductQuality.Low));
    pq.add(new Product("B", ProductQuality.High));
    pq.add(new Product("C", ProductQuality.Medium));
    Product m;/*from   w  w  w  .  j a  v  a 2 s  .  com*/
    while ((m = pq.poll()) != null)
        System.out.println(m.name + " Priority: " + m.priority);

    PriorityQueue<Product> pqRev = new PriorityQueue<Product>(3, new MessageComparator());

    pqRev.add(new Product("D", ProductQuality.Low));
    pqRev.add(new Product("E", ProductQuality.High));
    pqRev.add(new Product("F", ProductQuality.Medium));

    while ((m = pqRev.poll()) != null)
        System.out.println(m.name + " Priority: " + m.priority);
}

From source file:Main.java

public static <E> PriorityQueue<E> getPriorityQueue(int initialCapacity) {
    return new PriorityQueue<E>(initialCapacity);
}

From source file:Main.java

public static <E> PriorityQueue<E> createPriorityQueue(int initialCapacity) {
    return new PriorityQueue<E>(initialCapacity);
}

From source file:Main.java

public static <E> PriorityQueue<E> getPriorityQueue(Collection<? extends E> collection) {
    return new PriorityQueue<E>(collection);
}

From source file:Main.java

public static <E> PriorityQueue<E> createPriorityQueue(Collection<? extends E> collection) {
    if (collection == null) {
        return null;
    }/*from   www .j a v  a2  s.  c om*/

    return new PriorityQueue<E>(collection);
}

From source file:Main.java

public static <E> PriorityQueue<E> createPriorityQueue(int initialCapacity, Comparator<? super E> comparator) {
    if (comparator == null) {
        return new PriorityQueue<E>(initialCapacity);
    }/*  www. j a v  a 2 s  .  co  m*/

    return new PriorityQueue<E>(initialCapacity, comparator);
}

From source file:Main.java

public static <E> PriorityQueue<E> getPriorityQueue(PriorityQueue<? extends E> queue) {
    return new PriorityQueue<E>(queue);
}