public class ArrayStark {
private int maxSize;
private int top = -1;
private int[]stack;
public ArrayStark(int maxSize) {
this.maxSize = maxSize;
stack = new int[maxSize];
}
public boolean isEmpty(){
return top==-1;
}
public boolean isFull(){
if(top==maxSize-1)return true;
else return false;
}
public int pop(){
if(isEmpty())throw new RuntimeException("栈空");
int sum = stack[top];
top--;
return sum;
}
public void push(int sum){
if(isFull()){
System.out.println("栈满");
return;
}
stack[++top] = sum;
}
}