Skip to content

Commit

Permalink
using priority queue with objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankush1oo8 committed Mar 9, 2024
1 parent 9cd0dc6 commit a7d729d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Heap/PQWithObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ public int compareTo(student s2){
}
}
public static void main(String[] args) {
PriorityQueue<>pq=new PriorityQueue<>();
PriorityQueue<student>pq=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();
}

}
}

0 comments on commit a7d729d

Please sign in to comment.