stack.java

来自「一个可以读算术表达式」· Java 代码 · 共 38 行

JAVA
38
字号
/*
 * Created on 2004-12-2
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package calculator;

public class Stack
{  private Node top;
   public Stack()
   {  top = null; }
   public void push(Object obj)
   {  Node node = new Node(obj);
      node.next = top;
      top = node;
   }
   public Object pop() throws StackException
   {  if (top == null)
         throw new StackException("popping from an empty stack");
      else
      {  Object obj = top.data;
         top = top.next;
         return obj;
      }
   }
   public Object peek() throws StackException
   {  if (top == null)
         throw new StackException("peeking into empty stack");
      else
         return top.data;
   }
   public boolean isEmpty()
   {  return (top == null); }
}


⌨️ 快捷键说明

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