Skip to content

Priority Queue - (MAX heap) -Integers #85

@SharedMocha

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;
         }
         
     }

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