linkedstack.java

来自「java版的数据结构的完全代码 免费提供了 学习数据结构的请下载」· Java 代码 · 共 38 行

JAVA
38
字号
// Introduced in Chapter 6/** A linked Stack. */public class LinkedStack<E> implements Stack<E> {  /** The top ListNode in the Stack. */  private ListNode<E> top;  /** The Stack is initially empty. */  public LinkedStack() {    top = null;  }    public boolean isEmpty() {    return top == null;  }  public E peek() {    if (isEmpty()) {      throw new EmptyStructureException();    }    return top.getItem();  }  public E pop() {    if (isEmpty()) {      throw new EmptyStructureException();    }    E result = top.getItem();    top = top.getNext();    return result;  }  public void push(E target) {    top = new ListNode<E>(target, top);  }}

⌨️ 快捷键说明

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