stack.java

来自「WAP ide 代码」· Java 代码 · 共 58 行

JAVA
58
字号
package wapide;

import java.lang.*;
import java.util.*;
/**
 *  A helper class that simulates a stack object.
 *  Copyright (c) 2003
 * @author  Mark Busman
 * @version 1.0
 *
 * For License and contact information see WAPIDE.java
 */
public class Stack extends Object {

  /**
   * The number of itmes on the stack.
   */
  private int StackCounter = -1;
  /**
   * The actual stack object.
   */
  private ArrayList theStack = new ArrayList();

  /** Creates new Stack */
  public Stack() {
  }

  /** Push an object onto the stack.
   *  @param Object o - Any class as long as it is cast to an Object.
   */
  public void Push(Object o) {

    StackCounter++;
    theStack.add(o);
  }

  /** Pop's an object off the top of the stack.
   *  @return Object o
   */
  public Object Pop() {
    Object remObj = new Object();
    if (StackCounter > -1) {
      remObj = theStack.remove(StackCounter);
      StackCounter--;
     }
     return remObj;
  }

  /** Checks to see if the stack is empty.
   *  @return boolean - If true the stack is empty.
   */
  public boolean StackNotEmpty() {
    if (StackCounter > -1)
      return true;
    else
      return false;
  }
}

⌨️ 快捷键说明

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