/*-------------------------------------------------------------------*/ /* stack.c (Version 2: Function Modules) */ /*-------------------------------------------------------------------*/ #include "stack.h" #include #include void Stack_push(double pdStackArray[], int *piStackTop, int iMaxStackSize, double dItem) /* Push dItem onto the top of the stack represented by pdStackArray and piStackTop. iMaxStackSize indicates the maximum number of items that the stack can contain. */ { assert(pdStackArray != NULL); assert(piStackTop != NULL); assert(*piStackTop >= 0); assert(*piStackTop < iMaxStackSize); pdStackArray[*piStackTop] = dItem; ++*piStackTop; } double Stack_pop(double pdStackArray[], int *piStackTop) /* Pop and return the top item from the stack represented by pdStackArray and piStackTop. */ { assert(pdStackArray != NULL); assert(piStackTop != NULL); assert(*piStackTop > 0); --*piStackTop; return pdStackArray[*piStackTop]; }