listfifoqueue.java

来自「BOOK:Beginning Algorithms Code Example」· Java 代码 · 共 53 行

JAVA
53
字号
package com.wrox.algorithms.queues;import com.wrox.algorithms.lists.LinkedList;import com.wrox.algorithms.lists.List;/** * A First-In-First-Out (FIFO) {@link Queue} that uses a {@link List} internally. * */public class ListFifoQueue implements Queue {    /** The underlying list. */    private final List _list;    /**     * Default constructor. Uses a {@link LinkedList} as the underlying list.     */    public ListFifoQueue() {        this(new LinkedList());    }    /**     * Constructor.     *     * @param list The underlying list.     */    public ListFifoQueue(List list) {        _list = list;    }    public void enqueue(Object value) {        _list.add(value);    }    public Object dequeue() throws EmptyQueueException {        if (isEmpty()) {            throw new EmptyQueueException();        }        return _list.delete(0);    }    public void clear() {        _list.clear();    }    public int size() {        return _list.size();    }    public boolean isEmpty() {        return _list.isEmpty();    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?