Stack implemented on array. Maximum number of elements is size (therefore stack indexed from 0 .. size-1) tos (top of stack) /* initialize stack pointer */ tos = 0; /* test for full */ tos == size; /* test for empty */ tos == 0; /* push element x */ if (!full) s[tos++] = x; /* pop element */ if (!empty) return s[ --tos ]; /* print stack */ /* NOTE, this is not really a stack operation, but is handy for debugging */ /* from youngest to oldest */ if (!empty) for (n = tos; 0 <= n; n --) print s[n];