#include #include "intStack.h" // Define stack object and declare stack functions /* ================================================================== intStackInitialize(stackObj, N): Create a stack for N int's ================================================================== */ void intStackInitialize(intStack *stackObj, int N) { stackObj->s = (int *) calloc( sizeof(int), N ); stackObj->stackTop = -1; } /* ================================================================== intStackPush(stackObj,x): push x on stack ================================================================== */ void intStackPush( intStack *stackObj, int x) { (stackObj->stackTop)++; // Increment stack top stackObj->s[ stackObj->stackTop ] = x; // Store x in stack top } /* ================================================================== intStackPop(stackObj): pop stack top and return it ================================================================== */ int intStackPop( intStack *stackObj) { int r; r = stackObj->s[ stackObj->stackTop ]; // Save return value in r (stackObj->stackTop)--; // Decrement stack top return(r); } /* ================================================================== intStackPeek(stackObj): peek at top of stack ================================================================== */ int intStackPeek( intStack *stackObj) { return stackObj->s[ stackObj->stackTop ]; }