public class ArrayStack {
private int maxSize;
private int top = -1;
private int[] stack;
public ArrayStack(int maxSize) {
this.maxSize = maxSize;
stack = new int[maxSize];
}
public void push(int value){
if (isFull()) return;
top++;
stack[top] = value;
}
private boolean isFull() {
return top == maxSize - 1;
}
public int pop(){
if (isEmpty()) throw new RuntimeException("栈为空");
int value = stack[top];
top--;
return value;
}
private boolean isEmpty() {
return top == -1;
}
public void show(){
if (isEmpty()) return;
for (int i = top; i >= 0 ; i--) {
System.out.println(stack[i]);
}
}
}