Java 使用双链接列表的双端优先级队列
我正在尝试使用双链接列表实现一个双端优先级队列Java 使用双链接列表的双端优先级队列,java,generics,linked-list,comparator,doubly-linked-list,Java,Generics,Linked List,Comparator,Doubly Linked List,我正在尝试使用双链接列表实现一个双端优先级队列 public class ListDoubleEndedPriorityQueue<AnyType> implements DoubleEndedPriorityQueue<AnyType>{ private Comparator<? super AnyType> cmp; private Node<AnyType> first = null; private Node<AnyType>
public class ListDoubleEndedPriorityQueue<AnyType> implements DoubleEndedPriorityQueue<AnyType>{
private Comparator<? super AnyType> cmp;
private Node<AnyType> first = null;
private Node<AnyType> last = null;
private int size = 0;
公共类ListDoubleEndDPriorityQueue实现了DoubleEndDPriorityQueue{
private comparator可能您应该删除中断
,这样它将继续搜索。您完全正确,谢谢,但我仍然有比较器的问题如果您想了解比较器问题的任何信息,您最好告诉我们问题是什么?即,它在做什么,它与什么有什么不同这不是应该做的吗?看起来你的findMax()不考虑队列是emapty的情况吗?您可能还需要编辑问题并添加比较器代码。这就是问题所在。它应该是一个通用类,可用于多种类型,我的教授给我们发送了一个.class文件来测试它,但反编译后,它似乎与比较器或compa没有任何关系re method也许你应该删除中断
,这样它将继续搜索。你完全正确,谢谢,但是我仍然有比较器的问题。如果你想了解比较器问题的任何信息,你最好告诉我们问题是什么?即,它在做什么,它在哪些方面与它不同该怎么办?看起来你的findMax()也一样不考虑队列是emapty的情况吗?您可能还需要编辑问题并添加比较器代码。这就是问题所在。它应该是一个通用类,可用于多种类型,我的教授给我们发送了一个.class文件来测试它,但反编译后,它似乎与比较器或compa没有任何关系re方法
private static class Node<AnyType>{
private Node<AnyType> next;
private Node<AnyType> prev;
private AnyType e;
public Node(AnyType data){
next = prev = null;
e = data;
}
public AnyType getElement(){
return this.e;
}
public Node<AnyType> next(){
return next;
}
public Node<AnyType> prev(){
return prev;
}
public Node<AnyType> setNext(Node<AnyType> x){
return this.next = x;
}
public Node<AnyType> setPrev(Node<AnyType> x){
return this.prev = x;
}
}
public AnyType findMax ( ){
Node<AnyType> curr = first;
Node<AnyType> max = first;
int i = 0;
while(i < size){
if(cmp.compare(curr.e, max.e) > 0){
max = curr;
break;
}
curr = curr.next();
}
return max.e;
}