Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Thursday, May 25, 2017

Use PriorityQueue for Maxheap


PriorityQueue<Integer> maxHeap=new PriorityQueue<Integer>(
            new Comparator<Integer> () {
                public int compare(Integer a, Integer b) {
                return b - a;
            }
        });

Or

private 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

Stats