Skip to content

Priority Queue - (MAX heap) -Integers #85

Description

@SharedMocha

import java.util.*;
public class HelloWorld{

 public static void main(String []args){
     
     

     /*
     
     Comparator<String> temp = new Comparator<String>(){
         @Override
         public int compare(String s1,String s2){
             return s1.length() - s2.length();
         }
     };
     */
    System.out.println("Hello World");
    PQS pqs = new PQS();
    PriorityQueue<Integer> temp = new PriorityQueue<Integer>(4,pqs);
    temp.add(750);
    temp.add(500);
    temp.add(900);
    temp.add(100);
    
    while(!temp.isEmpty()){
        System.out.println(temp.poll());
    }
    
    
 }

}
class PQS implements Comparator{

         public int compare(Integer one,Integer two){
             System.out.println(one + "  "+ two);
             return two-one;
         }
         
     }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions