@@ -0,0 +1,2575 @@
+package java_problems.data_structures;%0D%0A%0D%0Aimport java.util.*;%0D%0A%0D%0Aclass Student1 %7B%0D%0A   private int token;%0D%0A   private String fname;%0D%0A   private double cgpa;%0D%0A   public Student1(int id, String fname, double cgpa) %7B%0D%0A      super();%0D%0A      this.token = id;%0D%0A      this.fname = fname;%0D%0A      this.cgpa = cgpa;%0D%0A   %7D%0D%0A   public int getToken() %7B%0D%0A      return token;%0D%0A   %7D%0D%0A   public String getFname() %7B%0D%0A      return fname;%0D%0A   %7D%0D%0A   public double getCgpa() %7B%0D%0A      return cgpa;%0D%0A   %7D%0D%0A%7D%0D%0A%0D%0Apublic class JavaPriorityQueue %7B%0D%0A%0D%0A    static class PQsort implements Comparator%3CStudent1%3E %7B%0D%0A        %0D%0A        public int compare(Student1 one, Student1 two) %7B%0D%0A            double oneCgpa = one.getCgpa();%0D%0A            double twoCgpa = two.getCgpa();%0D%0A            String oneFname = one.getFname();%0D%0A            String twoFname = two.getFname();%0D%0A            int oneToken = one.getToken();%0D%0A            int twoToken = two.getToken();%0D%0A            %0D%0A            if (oneCgpa %3C twoCgpa) %7B%0D%0A                return 1;%0D%0A            %7D else if (oneCgpa %3E twoCgpa) %7B%0D%0A                return -1;%0D%0A            %7D else %7B%0D%0A                int compareResult = oneFname.compareTo(twoFname);%0D%0A                %0D%0A                if (compareResult %3C 0) %7B%0D%0A                    return -1;%0D%0A                %7D else if (compareResult %3E 0) %7B%0D%0A                    return 1;%0D%0A                %7D else %7B%0D%0A                    if (oneToken %3C twoToken) %7B%0D%0A                        return -1;%0D%0A                    %7D else %7B%0D%0A                        return 1;%0D%0A                    %7D%0D%0A                %7D%0D%0A            %7D%0D%0A        %7D%0D%0A    %7D%0D%0A    %0D%0A    public static void main(String%5B%5D args) %7B%0D%0A      Scanner in = new Scanner(System.in);%0D%0A      int totalEvents = Integer.parseInt(in.nextLine());%0D%0A        %0D%0A      PQsort pqs = new PQsort();%0D%0A      PriorityQueue%3CStudent1%3E pq = new PriorityQueue%3C%3E(totalEvents, pqs);%0D%0A        %0D%0A      while(totalEvents%3E0)%7B%0D%0A         String event = in.next();%0D%0A         %0D%0A         if (event.equals(%22ENTER%22)) %7B%0D%0A             String fname = in.next();%0D%0A             double cgpa = in.nextDouble();%0D%0A             int id = in.nextInt();%0D%0A             %0D%0A             Student1 s = new Student1(id, fname, cgpa);%0D%0A             pq.offer(s);%0D%0A         %7D else %7B%0D%0A             pq.poll();%0D%0A         %7D%0D%0A           %0D%0A         totalEvents--;%0D%0A      %7D%0D%0A        %0D%0A      if (pq.size() == 0) %7B%0D%0A          System.out.println(%22EMPTY%22);%0D%0A      %7D else %7B%0D%0A    %09  Student1 s = pq.poll();%0D%0A    %09  while (s != null) %7B%0D%0A    %09%09  System.out.println(s.getFname());%0D%0A    %09%09  s = pq.poll();%0D%0A    %09  %7D%0D%0A      %7D%0D%0A      in.close();%0D%0A    %7D%0D%0A%7D

Add JavaPriorityQueue