-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstclear_bonus.c
72 lines (59 loc) · 2.02 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ledias-d <[email protected]> #+# +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024-10-11 12:55:26 by ledias-d #+# #+# */
/* Updated: 2024-10-11 12:55:26 by ledias-d ### ########.rio */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *tmp;
while (*lst)
{
tmp = (*lst)->next;
ft_lstdelone(*lst, del);
*lst = tmp;
}
*lst = NULL;
}
/*#include <stdio.h>
#include <string.h>
void del(void *content)
{
free(content);
}
int main(void)
{
t_list *node1;
t_list *node2;
t_list *node3;
// Alocando memória para o conteúdo dos nós
char *content1 = strdup("Node 1");
char *content2 = strdup("Node 2");
char *content3 = strdup("Node 3");
// Criando os nós
node1 = ft_lstnew(content1);
node2 = ft_lstnew(content2);
node3 = ft_lstnew(content3);
// Ligando os nós
node1->next = node2;
node2->next = node3;
// Verificando o conteúdo antes de limpar
printf("Antes de ft_lstclear:\n");
printf("Nó 1: %s\n", (char *)node1->content);
printf("Nó 2: %s\n", (char *)node2->content);
printf("Nó 3: %s\n", (char *)node3->content);
// Chamando ft_lstclear para limpar a lista
ft_lstclear(&node1, del);
// Verificando se a lista foi esvaziada
if (!node1)
printf("Depois de ft_lstclear: A lista está vazia.\n");
else
printf("Depois de ft_lstclear: A lista não está vazia.\n");
return (0);
}*/