-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstclear.c
71 lines (58 loc) · 1.85 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lpicoli- < lpicoli-@student.42porto.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/21 14:52:28 by lpicoli- #+# #+# */
/* Updated: 2022/11/23 10:02:15 by lpicoli- ### ########.fr */
/* */
/* ************************************************************************** */
/*
** 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.
*/
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void*))
{
t_list *tmp;
if(!*lst || !del)
return ;
while (*lst)
{
tmp = (*lst)->next;
del((*lst)->content);
free(*lst);
*lst = tmp;
}
}
/*void ft_freeNode(void *node)
{
node = NULL;
}
int main()
{
int a = 1;
int b = 2;
t_list *first;
t_list *second;
first = ft_lstnew(&a);
second = ft_lstnew(&b);
first->next = second;
second->next = NULL;
while (first)
{
printf("%d\n", *(int *)first->content);
first = first->next;
}
ft_lstclear(&first, &ft_freeNode);
if(first == NULL && second == NULL)
printf("It's null");
else
{
printf("It's not null");
}
}*/