phoenix13

导航

 

1.  override Comparator

import java.util.HashSet;
import java.util.Stack;
import java.util.Vector;
import java.util.Queue;
import java.util.PriorityQueue;
import java.util.Comparator;

public class test1 
{

    public static void main(String[] args) 
    {
        PriorityQueue<Integer> q1 = new PriorityQueue<Integer>(10,myComparator);
        Integer i1=new Integer(1);
        Integer i2=new Integer(2);
        q1.add(i1);
        q1.add(i2);
        while(!q1.isEmpty())
        {
              System.out.println(q1.poll());
        }

    }
    public static Comparator<Integer> myComparator = new Comparator<Integer>(){
        
        @Override
        public int compare(Integer c1, Integer c2) {
            return (int) (c2.intValue() - c1.intValue());
        }
    };

}

 

posted on 2014-02-11 06:53  phoenix13  阅读(801)  评论(0编辑  收藏  举报