使用双链接列表的双端优先级队列

时间:2016-10-01 21:09:07

标签: java generics linked-list comparator doubly-linked-list

我正在尝试使用双重LinkedList实现双端优先级队列

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;

这是我的节点类

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;
}

显然问题在于这个陈述:cmp.compare(curr.e,max.e) 但是我不知道我做错了可以有人请帮助我,谢谢。

0 个答案:

没有答案
相关问题