-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstclear_bonus.c
54 lines (47 loc) · 1.47 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kyungkim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/02 09:50:52 by kyungkim #+# #+# */
/* Updated: 2024/12/02 16:38:43 by kyungkim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *node;
if (!lst || !(*lst) || !del)
return ;
while (*lst)
{
node = *lst;
*lst = (*lst)->next;
del(node->content);
free(node);
}
}
/*
void delete_c(void *con)
{
(void) con;
return ;
}
int main(void)
{
t_list *start = ft_lstnew("hi");
t_list *start1 = ft_lstnew("42");
t_list *start2 = ft_lstnew("kay");
ft_lstadd_back(&start, start1);
ft_lstadd_back(&start, start2);
while (start)
{
printf("%p\n", start);
start = start->next;
}
ft_lstclear(&start, delete_c);
printf("after clear %p", start);
}
*/