Use PriorityQueue for Maxheap
PriorityQueue<Integer> maxHeap=new PriorityQueue<Integer>(
new Comparator<Integer> () {
public int compare(Integer a, Integer b) {
return b - a;
}
});
Orprivate static PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder());
Here we are comparing two integers using comparator to change the storing mechanism
0 Comments:
Post a Comment