└── java priority queue /java priority queue: -------------------------------------------------------------------------------- 1 | import java.util.Comparator; 2 | import java.util.PriorityQueue; 3 | import java.util.Scanner; 4 | 5 | import java.util.*; 6 | class Student implements Comparable{ 7 | String name = new String(); 8 | double cgpa; 9 | int id; 10 | public Student(String name,double cgpa,int id) 11 | { 12 | this.name = name; 13 | this.cgpa = cgpa; 14 | this.id = id; 15 | } 16 | public String getName(){ 17 | return this.name; 18 | } 19 | public int compareTo(Student s) 20 | { 21 | if(cgpa == s.cgpa) 22 | { 23 | if(name.compareTo(s.name) == 0) 24 | { 25 | if(id == s.id) 26 | return 0; 27 | else if (id > s.id) 28 | return 1; 29 | else 30 | return -1; 31 | } 32 | else 33 | return name.compareTo(s.name); 34 | } 35 | else if(cgpa > s.cgpa) 36 | return -1; 37 | else 38 | return 1; 39 | } 40 | } 41 | 42 | class Priorities{ 43 | public ArrayList getStudents(List events) 44 | { 45 | int n = events.size(); 46 | PriorityQueue pq = new PriorityQueue(); 47 | for(String i:events) 48 | { 49 | String[] s = new String[4]; 50 | s = i.split("\\s"); 51 | if(s.length>1) 52 | { 53 | pq.add(new Student(s[1],Double.valueOf(s[2]),Integer.valueOf(s[3]))); 54 | } 55 | else 56 | { 57 | pq.poll(); 58 | } 59 | } 60 | while(pq.size()>1) 61 | { 62 | System.out.println(pq.poll().name); 63 | } 64 | return new ArrayList(pq); 65 | } 66 | } 67 | --------------------------------------------------------------------------------