核心code:
//创建栈
class stack{
private int length;
private int front;
private int top;
private int[] stack;
//创建构造器
public stack(int length) {
this.length = length;
this.front = 0;
this.top = 0;
this.stack = new int[length];
}
//入栈操作
public boolean Instack(int a){
if(top == length) return false;
stack[top++] = a;
return true;
}
//出队操作
public boolean Popstack(){
if(top == front) return false;
top--;
return true;
}
//查看栈顶
public int Reserch(){
if(top == front) throw new RuntimeException("栈中为空");
return stack[top-1];
}
}