From 7bc3422dfece0f30cd0747e2449e7169ffdc11ed Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Mon, 5 Dec 2022 14:00:45 +0000 Subject: Only compile in code if it's used, and free memory when done --- 5.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to '5.c') diff --git a/5.c b/5.c index f404440..993c555 100644 --- a/5.c +++ b/5.c @@ -13,6 +13,16 @@ struct crate { }; +void +crate_free(struct crate * c) +{ + if (!c) + return; + crate_free(c->next); + free(c); +} + + int crates_move_9000(struct crate ** stack, int stacks, int dest, int src, int count) { @@ -78,6 +88,7 @@ crates_move_9001(struct crate ** stack, int stacks, int dest, int src, int count } +#ifdef CRATES_DUMP int crates_dump(struct crate ** stack, int stacks) { @@ -96,6 +107,7 @@ crates_dump(struct crate ** stack, int stacks) return 0; } +#endif int @@ -184,6 +196,11 @@ main(int argc, char ** argv) } fputc('\n', stdout); + for (i = 0; i < stacks; ++i) { + crate_free(stack[i]); + } + free(stack); + return 0; } -- cgit v1.2.1