队列课下作业

队列课下作业


一、补充书上代码15.5

public T dequeue() throws EmptyCollectionException {
        if (isEmpty()) throw new EmptyCollectionException("queue");
        T result = front.getElement();
        front = front.getNext();
        count--;
        if (isEmpty()) rear = null;
        return result;
    }

    public T first() throws EmptyCollectionException {
        if (isEmpty()) throw new EmptyCollectionException("queue");
        return front.getElement();
    }

    public boolean isEmpty() {
        return (count == 0);
    }

    public int size() {
        return count;
    }

    public String toString() {
        String result = "";
        LinearNode<T> current = front;
        while (current != null) {
            result = result + (current.getElement()).toString() + "
";
            current = current.getNext();
        }
        return result;
    }

二、单步跟踪排队情况

原文地址:https://www.cnblogs.com/zhanghaolin/p/7674876.html