先进后出
实现public class Stack {//声明一个数组private int[] arr;//声明头结点private int flage = 0; public Stack(int size) { arr = new int[size];} //添加数据public void add(int x) {//判断栈是否已满if (flage == arr.length) {//如果满了,实现扩容int[] brr = new int[arr.length * 2];for (int i = 0; i < arr.length; i++) {brr[i] = arr[i];}arr = brr;}arr[flage] = x;flage = flage + 1;} //获取的方法public Integer get() { //这个地方属于优化if(flage == 0) {return null;}int re = arr[flage-1];flage = flage -1; //很多同学在这个地方已陷入疑惑return re;}}