-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstiter_bonus.c
More file actions
87 lines (77 loc) · 1.89 KB
/
Copy pathft_lstiter_bonus.c
File metadata and controls
87 lines (77 loc) · 1.89 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: simarcha <simarcha@student.42barcel> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/21 17:35:53 by simarcha #+# #+# */
/* Updated: 2024/02/22 13:51:52 by simarcha ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
#include <unistd.h>
#include <stdio.h>
void f(void *content)
{
printf("%s\n", (char *)content);
}
*/
void ft_lstiter(t_list *lst, void (*f)(void *))
{
t_list *tmp;
if (!lst || !f)
return ;
while (lst != NULL)
{
tmp = lst;
f(tmp->content);
lst = lst->next;
}
}
/*
t_list *ft_lstnew(void *content)
{
t_list *new;
new = malloc(sizeof(t_list));
if (!new)
return (NULL);
new->content = content;
new->next = NULL;
return (new);
}
void ft_lstadd_back(t_list **lst, t_list *new)
{
if (!(*lst) || !new)
return ;
while ((*lst)->next != NULL)
*lst = (*lst)->next;
(*lst)->next = new;
}
#include <stdio.h>
void ft_lstprint(t_list *lst)
{
while (lst != NULL)
{
printf("%s\n", (char *)lst->content);
lst = lst->next;
}
}
int main(void)
{
t_list *node1;
t_list *node2;
t_list *tmp;
node1 = ft_lstnew("1");
node2 = ft_lstnew("2");
ft_lstadd_back(&node1, node2);
ft_lstiter(node1, f);
while (node1 != NULL)
{
tmp = node1;
free(tmp);
node1 = node1->next;
}
return (0);
}*/