public class MinAndMaxHeap {
static class MaxheapComparator implements Comparator<Integer> {
@Override
public int compare(Integer o1, Integer o2) {
return o2 - o1;
}
}
public static void main(String[] args) {
int[] arrForHeap= {3,5,2,7,0,1,6,4};
Queue<Integer> minHeap=new PriorityQueue<Integer>();
Queue<Integer> maxHeap=new PriorityQueue<Integer>(new MaxheapComparator());
for(int i=0;i<arrForHeap.length;i++) {
minHeap.add(arrForHeap[i]);
maxHeap.add(arrForHeap[i]);
}
while(!minHeap.isEmpty()) {
System.out.print(minHeap.poll()+" ");
}
System.out.println();
while(!maxHeap.isEmpty()) {
System.out.print(maxHeap.poll()+" ");
}
}
}