-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstmap_bonus.c
40 lines (37 loc) · 1.36 KB
/
ft_lstmap_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmanyani <mmanyani@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/16 12:03:53 by mmanyani #+# #+# */
/* Updated: 2024/11/20 11:54:19 by mmanyani ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *current;
t_list *list;
t_list *node;
void *tmp;
if (lst == NULL || f == NULL || del == NULL)
return (NULL);
current = lst;
list = NULL;
while (current != NULL)
{
tmp = f(current->content);
node = ft_lstnew(tmp);
if (node == NULL)
{
del(tmp);
ft_lstclear(&list, del);
return (NULL);
}
ft_lstadd_back(&list, node);
current = current->next;
}
return (list);
}