/* poly.c Implements "poly.h" interface. TYPE YOUR NAME AND THE DATE HERE */ #include #include #include #include "poly.h" /*** YOUR ENTIRE SOLUTION HERE ***/ /*** PART OF ASSIGNMENT SKELETON BELOW THIS COMMENT - DO NOT CHANGE ***/ int created = 0, freed = 0; /* for counting terms allocated in memory */ /* creates a new polynomial term (a list node), and increments count of terms created */ Term *newTerm(double coeff, unsigned exponent) { Term *node; if ((node = (Term *)malloc(sizeof(Term))) != NULL) { node->exponent = exponent; node->coeff = coeff; node->next = NULL; ++created; return node; } else { /* only if dynamic memory not available */ fprintf(stderr, "ran out of memory - might as well stop"); return NULL; } } /* frees memory allocated for a term, and increments freed count */ void freeTerm(Term *t) { free(t); ++freed; } /* returns number of terms created since execution began */ int termsCreated(void) { return created; } /* returns number of terms freed since execution began */ int termsFreed(void) { return freed; }