Skip to content

Commit 2958609

Browse files
committedOct 2, 2023
fix: add and use delete_stack
1 parent e5dad3f commit 2958609

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎data_structures/stack/dynamic_stack.c

+15
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,20 @@ int isempty(DArrayStack *ptr)
192192
*/
193193
int stack_size(DArrayStack *ptr) { return ptr->top + 1; }
194194

195+
/**
196+
* @brief Deallocates memory associated with a given DArrayStack.
197+
*
198+
* @param ptr Pointer to the stack structure to be deallocated.
199+
*/
200+
void delete_stack(DArrayStack *const ptr)
201+
{
202+
if (ptr == NULL) {
203+
return;
204+
}
205+
free(ptr->arrPtr);
206+
free(ptr);
207+
}
208+
195209
/**
196210
* @brief Self-test implementations
197211
* @returns void
@@ -237,6 +251,7 @@ static void test()
237251

238252
printf("\nTesting POP operation on empty stack: ");
239253
assert(pop(NewStack) == -1);
254+
delete_stack(NewStack);
240255
}
241256

242257
/**

0 commit comments

Comments
 (0)
Failed to load comments.