private static PriorityQueue<Url> unVisitedUrl = new PriorityQueue<Url>(1,new Comparator<Url>(){
@Override
public int compare(Url o1, Url o2) {
// TODO Auto-generated method stub
if(o1.getDegree()<o2.getDegree())
return -1 ;
else if(o1.getDegree()<o2.getDegree()){
return 0;
}else{
return 1;
}
}
}){
@Override
public boolean contains(Object e){
return false;
}
};
上面这段代码用的是java自带的优先队列,然后在使用时,重新写了他的contains方法,构造函数时调用了Comparator类,并且也重写了他的compare方法