-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstclear.c
executable file
·42 lines (36 loc) · 1.43 KB
/
ft_lstclear.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
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jchoy-me <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/20 12:29:33 by jchoy-me #+# #+# */
/* Updated: 2023/07/20 13:37:55 by jchoy-me ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
DESCRIPTION:
Deletes and frees the given node and every successor of that node, using the
function ’del’ and free(3).
Finally, the pointer to the list must be set to NULL.
PARAMETERS:
lst: The address of a pointer to a node.
del: The address of the function used to delete the content of the node.
EXTERNAL FUNCTIONS:
free
*/
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *ptr;
if (lst == NULL || del == NULL)
return ;
while (*lst != NULL)
{
ptr = (*lst)->next;
ft_lstdelone(*lst, del);
*lst = ptr;
}
*lst = NULL;
}