fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. PriorityQueue pq = new PriorityQueue<>(new PQComparator());
  14.  
  15. pq.add(4);
  16. pq.add(9);
  17. pq.add(10);
  18. pq.add(2);
  19. pq.add(3);
  20. pq.add(2);
  21. pq.add(3);
  22.  
  23. while (!pq.isEmpty()) {
  24. System.out.print(pq.poll() + " : ");
  25. }
  26. }
  27.  
  28.  
  29. }
  30.  
  31. class PQComparator implements Comparator<Integer> {
  32. @Override
  33. public int compare(Integer a, Integer b) {
  34. if (a > b) {
  35. return -1;
  36. } else if (a < b) {
  37. return 1;
  38. }
  39.  
  40. return 0;
  41. }
  42. }
Success #stdin #stdout 0.13s 55512KB
stdin
Standard input is empty
stdout
10 : 9 : 4 : 3 : 3 : 2 : 2 :