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