Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

min priority queue in java

// There is overflow problem when using simple lambda as comparator, as pointed out by Фима Гирин.
// PriorityQueue<Integer> pq = new PriorityQueue<>((x, y) -> y - x);

PriorityQueue<Integer> pq =new PriorityQueue<>((x, y) -> Integer.compare(y, x));

pq.add(10);
pq.add(5);
System.out.println(pq.peek());
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #min #priority #queue #java
ADD COMMENT
Topic
Name
3+5 =