/*-------------------------------------------------------------------*/ /* teststack.c (Version 2: Function Modules) */ /*-------------------------------------------------------------------*/ #include "stack.h" #include #include int main(int argc, char *argv[]) { /* A stack of doubles: */ double *pdStack1Array; int iStack1Top; /* A stack of doubles: */ double *pdStack2Array; int iStack2Top; pdStack1Array = (double*)calloc(10, sizeof(double)); iStack1Top = 0; Stack_push(pdStack1Array, &iStack1Top, 10, 1.1); Stack_push(pdStack1Array, &iStack1Top, 10, 2.2); while (iStack1Top > 0) printf("%g\n", Stack_pop(pdStack1Array, &iStack1Top)); free(pdStack1Array); pdStack2Array = (double*)calloc(20, sizeof(double)); iStack2Top = 0; Stack_push(pdStack2Array, &iStack2Top, 20, 3.3); Stack_push(pdStack2Array, &iStack2Top, 20, 4.4); while (iStack2Top > 0) printf("%g\n", Stack_pop(pdStack2Array, &iStack2Top)); free(pdStack2Array); return 0; } /* Output: 2.2 1.1 4.4 3.3 */