类比手枪弹夹
java实现
public class Stack { int[] stack; int top; public Stack(int num) { stack = new int[num]; top = -1; } public boolean pop(){ if (top == -1) return false; System.out.println(stack[top]); top--; return true; } public boolean push(int a){ if (top == stack.length - 1) return false; top++; stack[top] = a; return true; } }