Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package algorithm;
- import java.util.PriorityQueue;
- public class PriorityQueueDemo {
- public static void main(String[]args){
- PriorityQueue pq=new PriorityQueue();
- Student st1=new Student();
- st1.id=1;
- Student st2=new Student();
- st2.id=2;
- Student st3=new Student();
- st3.id=3;
- pq.add(st1);
- pq.add(st2);
- pq.add(st3);
- System.out.println(((Student)pq.peek()).id);
- }
- }
- class Student implements Comparable{
- int id;
- @Override
- public int compareTo(Object o) {
- Student st=(Student)o;
- if(this.id< st.id){
- return 1;
- }else if(this.id>st.id){
- return -1;
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement