有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

基于接口的Java链接队列

我正在尝试实现一个链接队列,其中每个节点代表一个人名以及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 Patron {

    String name;
    int coolLvl;
    boolean regular;

    /**
     * Constructor for Patron
     * @param n: name of the patron
     * @param c: the coolness factor of the patron
     * @param r: boolean indication whether the patron is a regular
     */
    public Patron(String n, int c, boolean r){
        this.name = n;
        this.coolLvl = c;
        this.regular = r;
    }

    public double getPriority(){
        return coolLvl;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public int getCoolLvl() {
        return coolLvl;
    }

    public void setCoolLvl(int coolLvl) {
        this.coolLvl = coolLvl;
    }

    public boolean isRegular() {
        return regular;
    }

    public void setRegular(boolean regular) {
        this.regular = regular;
    }
}

类节点

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

共 (0) 个答案