/* ** $Id: stack.c 739 2008-02-09 00:58:20Z phf $ */ #include #include "stack.h" // maximum size of the stack #define SIZE 8 // our internal representation of the stack; note that "index" // always points to the current "top" of the stack, so for an // empty stack, we have index == -1 static int index = -1; static int stack[SIZE]; // the remaining functions are hopefully obvious enough? make // sure you ask if anything is unclear! void push(int element) { assert(index < SIZE-1); index += 1; stack[index] = element; } void pop(void) { assert(index > -1); index -= 1; } int top(void) { assert(index > -1); return stack[index]; } int size(void) { return index+1; } int capacity(void) { return SIZE; }