Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

priority queue java comparator

// Java program to demonstrate working of 
// comparator based priority queue constructor
import java.util.*;
  
public class Example {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        // Creating Priority queue constructor having 
        // initial capacity=5 and a StudentComparator instance 
        // as its parameters
        PriorityQueue<Student> pq = new 
             PriorityQueue<Student>(5, new StudentComparator());
                  
             
        } 
    }
} 
  
class StudentComparator implements Comparator<Student>{
              
            // Overriding compare()method of Comparator 
                        // for descending order of cgpa
            public int compare(Student s1, Student s2) {
                if (s1.cgpa < s2.cgpa)
                    return 1;
                else if (s1.cgpa > s2.cgpa)
                    return -1;
                                return 0;
                }
        }
  
Comment

PREVIOUS NEXT
Code Example
Java :: java set operations 
Java :: loop array using stream java 
Java :: get all enum values java 
Java :: this keyword java 
Java :: if checkbox checked java 
Java :: How to return the elements of a matrix in spiral order, in Java? 
Java :: java how to know if there is something on arguments 
Java :: regex s+ 
Java :: final vs static keyword in java 
Java :: java array get index 
Java :: radix sort java 
Java :: how to convert errorBody to pojo in retrofit 
Java :: what is constructor in java 
Java :: java opp 
Java :: build libgdx jar 
Java :: localdate to string java 
Java :: ClassNotFoundException: org.springframework.ui.freemarker.FreeMarkerConfigurationFactory 
Java :: how to use enumUtils in java 
Java :: Button loginButton = new Button(this); loginButton.setText("Login"); Button register Button = new Button(this); register Button .gettext("Register"); 
Java :: JAVA Character Literals 
Java :: square star pattern in java 
Java :: calling java static method in kotlin 
Java :: java class array of objects 
Java :: list of strings java 
Java :: put arraylist in hashtable java 
Java :: math.sin in java 
Java :: java base64 decrypt script 
Java :: what is object in java 
Java :: java abstract modifier 
Java :: for each loop in java 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =