diff --git a/Heap/PQWithObjects.java b/Heap/PQWithObjects.java index a9628de..47bc6c8 100644 --- a/Heap/PQWithObjects.java +++ b/Heap/PQWithObjects.java @@ -15,7 +15,16 @@ public int compareTo(student s2){ } } public static void main(String[] args) { - PriorityQueue<>pq=new PriorityQueue<>(); + PriorityQueuepq=new PriorityQueue<>(/*to print in reverse order put 'Comparator.reverseOrder()'here */); + pq.add(new student("A", 4)); + pq.add(new student("B", 5)); + pq.add(new student("C", 2)); + pq.add(new student("D", 12)); + + while(!pq.isEmpty()){ + System.out.println(pq.peek().name+" -> "+pq.peek().rank); + pq.remove(); + } } }