/*------------------------------------------------------------------*/ /* teststack.c */ /*------------------------------------------------------------------*/ #include #include #include "stack.h" int main(int argc, char *argv[]) /* Test the Stack ADT. */ { Stack_T oStack1; Stack_T oStack2; double d1 = 1.1; double d2 = 2.2; double d3 = 3.3; double *pd; /* Create and use a Stack of strings. */ oStack1 = Stack_new(); Stack_push(oStack1, "Ruth"); Stack_push(oStack1, "Gehrig"); Stack_push(oStack1, "Mantle"); Stack_push(oStack1, "Jeter"); while (! Stack_isEmpty(oStack1)) printf("%s\n", (char*)Stack_pop(oStack1)); Stack_free(oStack1); /* Create and use a Stack of doubles. */ oStack2 = Stack_new(); Stack_push(oStack2, &d1); Stack_push(oStack2, &d2); Stack_push(oStack2, &d3); while (! Stack_isEmpty(oStack2)) { pd = (double*)Stack_pop(oStack2); printf("%g\n", *pd); } Stack_free(oStack2); return 0; }