-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpriority.java
More file actions
30 lines (27 loc) · 807 Bytes
/
Copy pathpriority.java
File metadata and controls
30 lines (27 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.PriorityQueue;
import java.util.*;
public class priority {
static class Student implements Comparable<Student> {
String name;
int rank;
Student(String name, int rank){
this.name = name;
this.rank = rank;
}
@Override
public int compareTo(Student s2){
return this.rank - s2.rank;
}
}
public static void main(String[] args) {
PriorityQueue<Student> pq = new PriorityQueue<>();
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();
}
}
}