Free list after each test

This commit is contained in:
Peter J. Holzer 2020-10-24 01:52:00 +02:00 committed by Peter J. Holzer
parent 259302b368
commit d6ecce40f9
1 changed files with 12 additions and 0 deletions

View File

@ -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);
}
}