/*------------------------------------------------------------------*/ /* teststack.c */ /* Author: Bob Dondero */ /* A client of a generic Stack ADT */ /*------------------------------------------------------------------*/ #include #include #include "stack.h" int main(void) /* Test the Stack ADT. Return 0. */ { 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; }