public class Stack {
  private long[] stackArray;
  private int maxSize;
  private int top;

  public Stack(int maxSize) {
    this.maxSize = maxSize;
    this.stackArray = new long[this.maxSize];
    this.top = -1;
  }

  public void push(long value) {
    stackArray[++top] = value;
  }

  public long pop() {
    return stackArray[top--];
  }

  public long peek() {
    return stackArray[top];
  }

  public boolean isEmpty() {
    return top == -1 ? true : false;
  }

  public boolean isFull() {
    return top == (maxSize - 1) ? true : false;
  }
}

posted @ 2015-08-12 14:39  studyForAndroid  阅读(114)  评论(0)    收藏  举报