栈的数组实现

//stack包含两个元素:最顶的位置,保存数据的数组
特性:
1. pop:当元素数量为0的时候输出-1,否则输出数组最高位的值,并将数组的长度-1
2. push:首先将数组的长度伸长1,然后将值放在这个位置
public
class Stack{ private int topOfStack = 0; private int[] theArray =new int[1000]; public int pop(){ if(topOfStack == 0){ return -1; } return theArray[topOfStack--]; } public void push(int val){ theArray[++topOfStack] = val; } }
原文地址:https://www.cnblogs.com/zhangchiblog/p/7989128.html