-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstmap.c
61 lines (52 loc) · 1.72 KB
/
ft_lstmap.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tauer <tauer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 11:32:41 by tauer #+# #+# */
/* Updated: 2023/11/13 14:03:05 by tauer ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *cpy_f;
t_list *new_node;
cpy_f = NULL;
while (lst)
{
new_node = ft_lstnew(f(lst->content));
if (new_node == NULL)
{
ft_lstclear(&cpy_f, del);
return (NULL);
}
ft_lstadd_back(&cpy_f, new_node);
if (cpy_f == NULL)
return (NULL);
lst = lst->next;
}
return (cpy_f);
}
// void del_node(void *content)
// {
// free(content);
// }
// int main(void)
// {
// t_list *first = ft_lstnew("first one");
// t_list *second = ft_lstnew("second one");
// t_list *third = ft_lstnew("third one");
// first->next = second;
// second->next = third;
// third->next = NULL;
// t_list *stock = ft_lstmap(first, ft_strupcase, del_node);
// while(stock)
// {
// printf("%s\n", stock->content);
// stock = stock->next;
// }
// return (0);
// }