List of usage examples for java.util PriorityQueue add
public boolean add(E e)
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> p = new NoDuplicates<Integer>(); p.add(1); p.add(2);//from ww w. ja v a 2s . com p.add(1); for (int i = 0; i <= 2; i++) { System.out.println(p.poll()); } }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); for (int i = 0; i < 10; i++) { prq.add(i); }/* w w w .jav a 2 s.c o m*/ System.out.println(prq); }
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); }/*from w ww. j a v a 2 s . co m*/ System.out.println(prq); }
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 av a 2 s .co m*/ 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 void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); for (int i = 3; i < 10; i++) { prq.add(i); }/*from ww w . ja va2s . co m*/ System.out.println("Size of the queue is: " + prq.size()); System.out.println(prq); }
From source file:PriorityQueueTest.java
public static void main(String[] args) { PriorityQueue<GregorianCalendar> pq = new PriorityQueue<GregorianCalendar>(); pq.add(new GregorianCalendar(1906, Calendar.DECEMBER, 9)); // G. Hopper pq.add(new GregorianCalendar(1815, Calendar.DECEMBER, 10)); // A. Lovelace pq.add(new GregorianCalendar(1903, Calendar.DECEMBER, 3)); // J. von Neumann pq.add(new GregorianCalendar(1910, Calendar.JUNE, 22)); // K. Zuse System.out.println("Iterating over elements..."); for (GregorianCalendar date : pq) System.out.println(date.get(Calendar.YEAR)); System.out.println("Removing elements..."); while (!pq.isEmpty()) System.out.println(pq.remove().get(Calendar.YEAR)); }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); for (int i = 0; i < 10; i++) { prq.add(i); }/*from www . j a v a2 s . c o m*/ System.out.println(prq); prq.clear(); System.out.println(prq); }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); for (int i = 0; i < 10; i++) { prq.add(i); }/*w ww . j av a2 s . c o m*/ System.out.println(prq); // check if queue contains 5 boolean b = prq.contains(5); System.out.println("Priority queue contains 5: " + b); }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); for (int i = 3; i < 10; i++) { prq.add(i); }/*from www . j a v a2 s . co m*/ System.out.println(prq); // get the head from the queue Integer head = prq.peek(); System.out.println("Head of the queue is: " + head); }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); for (int i = 0; i < 10; i++) { prq.add(i); }/* w w w. j av a2s . co m*/ System.out.println(prq); // add using offer() function call prq.offer(122); System.out.println(prq); }