diff --git a/c/linked-list.c b/c/linked-list.c index 2b5e984..b7ce946 100644 --- a/c/linked-list.c +++ b/c/linked-list.c @@ -58,6 +58,17 @@ resultT traverse(nodeT *p) { } } +void teardown(nodeT *p) { + nodeT *first = p; + do { + nodeT *next = p->next; + p->value = 0; + p->next = NULL; + free(p); + p = next; + } while (p != first); +} + int main (void) { size_t n; for (n = 2; ; n *= 2) { @@ -65,5 +76,6 @@ int main (void) { resultT r = traverse(p); printf("%zu %zu %g %g %" PRIuFAST64 "\n", n, r.count, r.total_time, r.avg_time, r.sum); + teardown(p); } }