mirror of
https://github.com/theoludwig/libcproject.git
synced 2025-05-21 23:21:15 +02:00
feat: add stack_free
This commit is contained in:
13
lib/stack.c
13
lib/stack.c
@ -35,3 +35,16 @@ void *stack_pop(struct stack *stack) {
|
||||
stack->length = stack->length - 1;
|
||||
return data;
|
||||
}
|
||||
|
||||
void stack_free(struct stack *stack) {
|
||||
if (stack == NULL) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
struct stack_node *node = stack->first;
|
||||
while (node != NULL) {
|
||||
struct stack_node *node_next = node->next;
|
||||
free(node);
|
||||
node = node_next;
|
||||
}
|
||||
free(stack);
|
||||
}
|
||||
|
@ -42,4 +42,10 @@ void stack_push(struct stack *stack, void *data);
|
||||
*/
|
||||
void *stack_pop(struct stack *stack);
|
||||
|
||||
/**
|
||||
* @brief Frees the stack.
|
||||
* @since v2.1.0
|
||||
*/
|
||||
void stack_free(struct stack *stack);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user