import java.util.Arrays; public class StackDemo { private int maxSize; private long[] stackArray; private int top; // 构造器 public StackDemo(int s){ // 初始化栈 maxSize = s; stackArray = new long[maxSize]; top = -1; } // 入栈 public void push(long element){…