Skip to content

Commit

Permalink
fix: add and use delete_stack
Browse files Browse the repository at this point in the history
  • Loading branch information
vil02 committed Sep 13, 2023
1 parent db3d6e2 commit 7f465df
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions data_structures/stack/dynamic_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -237,6 +251,7 @@ static void test()

printf("\nTesting POP operation on empty stack: ");
assert(pop(NewStack) == -1);
delete_stack(NewStack);
}

/**
Expand Down

0 comments on commit 7f465df

Please sign in to comment.