#include "stack.h" #ifdef DEBUG #include static int nelem = 0; #endif DEBUG int isempty( TOP t) { return (t == NULLVAL); } DATA top(TOP t) { return (t -> d); } void pop(TOP *t, DATA *x) { TOP t1 = *t; #ifdef DEBUG extern int nelem; #endif DEBUG if(! isempty(t1) ){ *x = t1->d; *t = t1->next; free(t1); #ifdef DEBUG nelem--; printf("leaving pop nelem = %d\n",nelem); #endif DEBUG } else printf("\npop: empty stack\n"); } void push( TOP *t, DATA x) { TOP temp; #ifdef DEBUG extern int nelem; #endif DEBUG temp = (TOP) malloc(sizeof(ELEMENT)); temp->d = x; temp->next = *t; *t = temp; #ifdef DEBUG nelem++; printf("leaving push nelem = %d\n",nelem); #endif DEBUG }