why are priority queues in java and cpp different code example
Example 1: priority queue in java
import java.util.PriorityQueue;
import java.util.Iterator;
class Main {
public static void main(String[] args) {
PriorityQueue<Integer> numbers = new PriorityQueue<>();
numbers.add(4);
numbers.add(2);
numbers.add(1);
System.out.print("PriorityQueue using iterator(): ");
Iterator<Integer> iterate = numbers.iterator();
while(iterate.hasNext()) {
System.out.print(iterate.next());
System.out.print(", ");
}
}
}
Example 2: implemetation of priority queue in c++
priority_queue<int> pq;
priority_queue <int, vector<int>, greater<int> > pq;
#define pp pair<int, int>
priority_queue <pp, vector<pp>, greater<pp> > pq;