List of usage examples for java.util PriorityQueue PriorityQueue
public PriorityQueue()
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 a v 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>(); for (int i = 3; i < 10; i++) { prq.add(i);/*from w w w . j ava 2 s. c o m*/ } System.out.println("Size of the queue is: " + prq.size()); 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);/*from w ww .j av 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);/*from w w w. ja va 2 s . co 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 w ww .j a v a 2 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);/*from ww w . ja v a 2s .co m*/ } System.out.println(prq); // add using offer() function call prq.offer(122); System.out.println(prq); }
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 w w w .j a v a2 s .c om*/ } System.out.println(prq); // get the head from the queue Integer head = prq.poll(); System.out.println("Head of the queue is: " + head); System.out.println(prq); }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); // insert values in the queue for (int i = 3; i < 10; i++) { prq.add(i);//from w w w. ja va 2s. co m } System.out.println(prq); // remove 7 from the queue boolean isremoved = prq.remove(7); System.out.println("Return value after remove: " + isremoved); System.out.println(prq); }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); // insert values in the queue prq.add(6);//from w w w .jav a 2 s .c o m prq.add(9); prq.add(5); prq.add(64); prq.add(6); System.out.println(prq); // get objects from the queue Object[] arr = prq.toArray(); for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); // insert values in the queue prq.add(1);// w ww. j av a2s . c o m prq.add(2); prq.add(1); prq.add(64); prq.add(1); System.out.println(prq); // create arr1 Integer[] arr1 = new Integer[5]; // use toArrsy() method Integer[] arr2 = prq.toArray(arr1); for (int i = 0; i < arr1.length; i++) { System.out.println(arr1[i]); } for (int i = 0; i < arr2.length; i++) { System.out.println(arr2[i]); } }