-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstclear.c
39 lines (36 loc) · 1.52 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: crea <crea@student.42roma.it> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/19 19:45:24 by crea #+# #+# */
/* Updated: 2024/02/12 00:44:10 by crea ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* ft_lstclear:
** Clears the entire list pointed to by 'lst', using the function 'del'
** to free the content of each node.
** Iterates through the list, deletes the content of each node using 'del',
** and frees the node itself.
** Sets the list pointer to NULL after all nodes are cleared.
** If 'lst' or 'del' is NULL, the function does nothing.
*/
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *current;
t_list *next;
if (!lst|| !del)
return ;
current = *lst;
while (current)
{
next = current->next;
del(current->content);
free(current);
current = next;
}
*lst = NULL;
}