package day4;
public class Stack {
//java中栈的数据结构
int[] array;
int top;
Stack(){
this.array = new int[100];
this.top = top;
}
public void push(int v){
//进栈过程
this.array[this.top++] = v;
}
public int pop(){
//出栈和弹栈
return array[--this.top];
}
public int peek(){
//查询栈顶元素
return this.array[this.top-1];
}
public int size(){
//返回栈的长度
return this.top;
}
public boolean isEmpty(){
//判断栈是否为空
return this.top == 0;
}
}
用java写栈的数据结构
最新推荐文章于 2023-02-23 17:21:17 发布