-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstclear_bonus.c
38 lines (35 loc) · 1.52 KB
/
ft_lstclear_bonus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: flverge <flverge@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 15:19:11 by flverge #+# #+# */
/* Updated: 2024/09/22 17:21:08 by flverge ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @file ft_lstclear_bonus.c
* @brief Clears and frees the entire list.
*
* This function iterates through the list pointed to by `lst`, applying the
* function `del` to the content of each element, and then frees the element.
* The pointer to the list is set to NULL after the list is cleared.
*
* @param lst A pointer to the pointer to the first element of the list.
* @param del A function pointer to a function used to delete the content
* of an element.
*/
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *temp;
while (*lst)
{
temp = (*lst)->next;
del((*lst)->content);
free(*lst);
*lst = temp;
}
}