Solution 1:
Min Heap:
a -> a.getWeight()
Max Heap:
a -> -a.getWeight()
Example:
PriorityQueue<Edge> PriorityQueue = new PriorityQueue<>(Comparator.comparingDouble(a -> a.getWeight()));
PriorityQueue = new PriorityQueue<>(Comparator.comparingDouble(a -> -a.getWeight()));
Solution 2:
Min Heap:
Edge::getWeight
Max Heap:
(Edge::getWeight).reversed()
Example:
PriorityQueue<Edge> PriorityQueue = new PriorityQueue<>(Comparator.comparingDouble(Edge::getWeight));
PriorityQueue = new PriorityQueue<>(Comparator.comparingDouble(Edge::getWeight).reversed());
Solution 3:
Min Heap:
(a, b) -> a.getStart() - b.getStart()
(a, b) -> (int) (a.getWeight() - b.getWeight())
Max Heap:
(a, b) -> b.getStart() - a.getStart()
(a, b) -> (int) (b.getWeight() - a.getWeight())
Example:
PriorityQueue<Edge> PriorityQueue = new PriorityQueue<>((a, b) -> a.getStart() - b.getStart());
PriorityQueue = new PriorityQueue<>((a, b) -> (int) (a.getWeight() - b.getWeight()));
PriorityQueue = new PriorityQueue<>((a, b) -> b.getStart() - a.getStart());
PriorityQueue = new PriorityQueue<>((a, b) -> (int) (b.getWeight() - a.getWeight()));