public class MyStack {
private int maxSize;
private int[] arr;
private int top;
//初始化栈
public MyStack(int size) {
this.maxSize=size;
arr = new int[maxSize];
top=-1;
}
//压栈
public void push(int value) {
top++;
arr[top]=value;
// arr[++top]=value;
}
//出栈
public int pop() {
return arr[top--];
}
//访问栈顶元素
public int peek() {
return arr[top];
}
//栈是否为空
public boolean isEmpty() {
return (top == -1);
}
//栈满否
public boolean isFull() {
return (top==maxSize-1);
}
}