From 295860936e5fcb87816bbb97a16e518c7d594238 Mon Sep 17 00:00:00 2001 From: vil02 Date: Wed, 13 Sep 2023 17:45:02 +0200 Subject: [PATCH] fix: add and use `delete_stack` --- data_structures/stack/dynamic_stack.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/data_structures/stack/dynamic_stack.c b/data_structures/stack/dynamic_stack.c index 482896eabd..9f9147fb0e 100644 --- a/data_structures/stack/dynamic_stack.c +++ b/data_structures/stack/dynamic_stack.c @@ -192,6 +192,20 @@ int isempty(DArrayStack *ptr) */ int stack_size(DArrayStack *ptr) { return ptr->top + 1; } +/** +* @brief Deallocates memory associated with a given DArrayStack. +* +* @param ptr Pointer to the stack structure to be deallocated. +*/ +void delete_stack(DArrayStack *const ptr) +{ + if (ptr == NULL) { + return; + } + free(ptr->arrPtr); + free(ptr); +} + /** * @brief Self-test implementations * @returns void @@ -237,6 +251,7 @@ static void test() printf("\nTesting POP operation on empty stack: "); assert(pop(NewStack) == -1); + delete_stack(NewStack); } /**