mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
fix: add and use delete_stack
This commit is contained in:
parent
e5dad3fa8d
commit
295860936e
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user