基于接口的Java链接队列

基于接口的Java链接队列,java,linked-list,Java,Linked List,我正在尝试实现一个链接队列,其中每个节点代表一个人名以及1-10之间的“酷度因子”,以及他们是否是普通人(用户类)。在此基础上,它们首先以最高数字的顺序插入队列,如果并列,则正则表达式获得优先级。我对与诸如此类的人一起工作感到困惑。我相信我的插入已经接近成功了,我只是在《思想》中发表了评论,它并不能说明优先级。我的语法也很混乱。我正在尝试将一个Python链接队列配置为java实现 类链接队列 public class LinkedQueue <T extends Prioritizabl

我正在尝试实现一个链接队列,其中每个节点代表一个人名以及1-10之间的“酷度因子”,以及他们是否是普通人(用户类)。在此基础上,它们首先以最高数字的顺序插入队列,如果并列,则正则表达式获得优先级。我对与诸如此类的人一起工作感到困惑。我相信我的插入已经接近成功了,我只是在《思想》中发表了评论,它并不能说明优先级。我的语法也很混乱。我正在尝试将一个Python链接队列配置为java实现

类链接队列

public class LinkedQueue <T extends Prioritizable> implements PriorityQueue<T> {

    private Node<T> head;
    //private T head = null;
    private int queueSize = 0;

    public LinkedQueue() {

    }
    public boolean isEmpty() {
        if(queueSize == 0){
            return true;
        }
        return false;
    }

    /**
     * Inserts given node into the queue in the proper position based on     coolness number
     */
    public void insert(T toInsert) {
        Node<T> tempNode = (Node<T>) toInsert;
        // Create an int w/ the node's coolness
        // int tempCool = ^

        Node<T> currentNode = (Node<T>) head;
        while(currentNode.getNext() != null){
            //loop like above except by "coolness" | while (     currentNode.getCoolness < currentNode.getNext.getCoolness)
                currentNode = currentNode.getNext();
        }
        currentNode.setNext(tempNode);
        queueSize++;
    }

    public T dequeue() {
        Node<T> currentNode = (Node<T>) head;
        if(head != null){
            //Remove head of the queue
        }
        queueSize--;
        return (T) currentNode;
    }
}
类节点

public class Node<T> {
    /** This field holds the value. */
    private T data;
    /** This field connects this Node to the next one. */
    private Node< T > next;

    /**
     * Initialize a new node.
     * @param data the data value to be stored in the node
     * @param next the successor to this node, or null if none
     */
    public Node( T data, Node< T > next ) {
        this.data = data;
        this.next = next;
    }

    /**
     * Accessor for link.
     * @return the successor to this node, or null if none
     */
    public Node< T > getNext() {
        return next;
    }

    /**
     * Mutator for link.
     * @param next new successor for this node, or null if this
     *     is now the last node of the list
     */ 
    public void setNext( Node< T > next ) {
        this.next = next;
    }

    /**
     * Accessor for value.
     * @return the value stored in this node
     */
    public T getData() {
        return data;
    }

    /**
     * Mutator for value.
     * @param data new value to be stored in this node
     */
    public void setData( T data ) {
        this.data = data;
    }

    /**
     * A string representation of this node.
     * Note that toString will be called on the successor,
     * so a long linked list will produce a large string.
     */
    @Override
    public String toString() {
        return "Node{" +
                "data=" + data +
                ", next=" + next +
                '}';
    }
公共类节点{
/**此字段保存该值*/
私有T数据;
/**此字段将此节点连接到下一个节点*/
私有节点next;
/**
*初始化一个新节点。
*@param data要存储在节点中的数据值
*@param位于此节点的后续节点旁边,如果没有,则为null
*/
公共节点(T数据,节点next){
这个数据=数据;
this.next=next;
}
/**
*链接的访问器。
*@返回此节点的后续节点,如果没有,则返回null
*/
公共节点getNext(){
下一步返回;
}
/**
*链接的变异体。
*@param此节点的下一个新继承者,如果
*现在是列表的最后一个节点
*/ 
公共void setNext(节点next){
this.next=next;
}
/**
*值的访问器。
*@返回存储在此节点中的值
*/
公共T getData(){
返回数据;
}
/**
*值的变异子。
*@param data要存储在此节点中的新值
*/
公共无效设置数据(T数据){
这个数据=数据;
}
/**
*此节点的字符串表示形式。
*请注意,toString将在继承者上调用,
*因此,一个长链表将产生一个大字符串。
*/
@凌驾
公共字符串toString(){
返回“节点{”+
“数据=”+数据+
“,next=“+next”+
'}';
}

首先,这是太多的代码,对您需要帮助的特定问题几乎没有足够的关注。其次,除非您有非常具体的理由使用链表实现,一般来说,优先级队列实现为,而不是链表。在链表中维护排序顺序是一个O(n)操作,而不是O(对数n)或O(1)对于堆实现。这闻起来像是家庭作业,但很可能不是。我可以推荐使用而不是自己滚动吗?然后你所要做的就是实现
可比的
比较器
。埃塔:等等,刚刚注意到你有…
实现优先级队列
?好的,但是
优先级队列
不是一个界面,你怎么能有
实现
public class Node<T> {
    /** This field holds the value. */
    private T data;
    /** This field connects this Node to the next one. */
    private Node< T > next;

    /**
     * Initialize a new node.
     * @param data the data value to be stored in the node
     * @param next the successor to this node, or null if none
     */
    public Node( T data, Node< T > next ) {
        this.data = data;
        this.next = next;
    }

    /**
     * Accessor for link.
     * @return the successor to this node, or null if none
     */
    public Node< T > getNext() {
        return next;
    }

    /**
     * Mutator for link.
     * @param next new successor for this node, or null if this
     *     is now the last node of the list
     */ 
    public void setNext( Node< T > next ) {
        this.next = next;
    }

    /**
     * Accessor for value.
     * @return the value stored in this node
     */
    public T getData() {
        return data;
    }

    /**
     * Mutator for value.
     * @param data new value to be stored in this node
     */
    public void setData( T data ) {
        this.data = data;
    }

    /**
     * A string representation of this node.
     * Note that toString will be called on the successor,
     * so a long linked list will produce a large string.
     */
    @Override
    public String toString() {
        return "Node{" +
                "data=" + data +
                ", next=" + next +
                '}';
    }