⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 liststack.java

📁 BOOK:Beginning Algorithms Code Examples
💻 JAVA
字号:
package com.wrox.algorithms.stacks;import com.wrox.algorithms.lists.LinkedList;import com.wrox.algorithms.lists.List;import com.wrox.algorithms.queues.EmptyQueueException;/** * A {@link Stack} that uses a {@link List} internally. * */public class ListStack implements Stack {    /** The underlying list. */    private final List _list = new LinkedList();    public void push(Object value) {        _list.add(value);    }    public Object pop() throws EmptyStackException {        if (isEmpty()) {            throw new EmptyStackException();        }        return _list.delete(_list.size() - 1);    }    public Object peek() throws EmptyStackException {        Object result = pop();        push(result);        return result;    }    public void enqueue(Object value) {        push(value);    }    public Object dequeue() throws EmptyQueueException {        try {            return pop();        } catch (EmptyStackException e) {            throw new EmptyQueueException();        }    }    public void clear() {        _list.clear();    }    public int size() {        return _list.size();    }    public boolean isEmpty() {        return _list.isEmpty();    }}

⌨️ 快捷键说明

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