/* The stack pointer always points to the first free position on the stack. This is the common way to implement the stack. */ int stack [30]; int stackPointer = 0; void push(int element) { stack[stackPointer] = element; stackPointer++; } bool isEmpty() { return stackPointer == 0; } int pop() { if (!isEmpty()) { stackPointer--; return stack[stackPointer]; } }