Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package algorithm;
  2.  
  3. import java.util.PriorityQueue;
  4.  
  5. public class PriorityQueueDemo {
  6.    
  7.     public static void main(String[]args){
  8.         PriorityQueue pq=new PriorityQueue();
  9.         Student st1=new Student();
  10.         st1.id=1;
  11.         Student st2=new Student();
  12.         st2.id=2;
  13.         Student st3=new Student();
  14.         st3.id=3;
  15.         pq.add(st1);
  16.         pq.add(st2);
  17.         pq.add(st3);
  18.         System.out.println(((Student)pq.peek()).id);
  19.     }
  20. }
  21.  
  22. class Student implements Comparable{
  23.     int id;
  24.     @Override
  25.     public int compareTo(Object o) {
  26.         Student st=(Student)o;
  27.         if(this.id< st.id){
  28.             return 1;
  29.         }else if(this.id>st.id){
  30.             return -1;
  31.         }
  32.         return 0;
  33.     }
  34. }