min heap and max heap using priority queue code example
Example 1: min heap priority queue c++
#include<queue>
std::priority_queue <int, std::vector<int>, std::greater<int> > minHeap;
Example 2: create a min heap in java using priority queue
int arr[]={1,2,1,3,3,5,7};
PriorityQueue<Integer> a=new PriorityQueue<>();
for(int i:arr){
a.add(i);
}
while(!a.isEmpty())
System.out.println(a.poll());