-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstclear.c
72 lines (64 loc) · 1.89 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
72
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sde-silv <sde-silv@student.42berlin.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/04 13:53:52 by sde-silv #+# #+# */
/* Updated: 2023/10/04 13:57:25 by sde-silv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
void del(void *ptr)
{
if (ptr)
{
ptr = 0;
}
}
*/
void ft_lstclear(t_list **lst, void (*del)(void*))
{
t_list *temp;
while (*lst)
{
(del)((*lst)->content);
temp = *lst;
*lst = temp->next;
free (temp);
}
*lst = 0;
}
/*
int main(void)
{
t_list *head;
t_list *current;
t_list **lst;
t_list *last;
int size;
head = ft_lstnew((void *)20);
*lst = head;
head->next = ft_lstnew((void *)30);
ft_lstadd_front(lst, ft_lstnew((void *)10));
ft_lstadd_back(lst, ft_lstnew((void *)40));
current = *lst;
size = ft_lstsize(*lst);
printf("size: %d\n", size);
while (current != NULL)
{
printf("%zu\n", (size_t)current->content);
current = current->next;
}
last = ft_lstlast(*lst);
printf("last: %zu\n", (size_t)(last->content));
current = *lst;
ft_lstclear(&head, del);
printf("Current: %zu\n", (size_t)(current)->content);
current = current->next;
printf("Current: %zu\n", (size_t)(current)->content);
return (0);
}
*/