You are viewing a single comment's thread. Return to all comments →
Just use this comparator in the Student class and while instantiating the priority queue pass it as an argument.
public static Comparator<Student> studentComparator = new Comparator<Student>(){ @Override public int compare(Student student1, Student student2) { if(student1.getCgpa()<student2.getCgpa()) return 1; else if(student1.getCgpa()>student2.getCgpa()) return -1; else{ if(!student1.getFname().equals(student2.getFname())) return student1.getFname().compareTo(student2.getFname()); else{ return(student1.getToken()-student2.getToken()); } } } };
Sorry for the bad indentation!
Seems like cookies are disabled on this browser, please enable them to open this website
Java Priority Queue
You are viewing a single comment's thread. Return to all comments →
Just use this comparator in the Student class and while instantiating the priority queue pass it as an argument.
Sorry for the bad indentation!