-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstmap.c
37 lines (33 loc) · 1.3 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aymoulou <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/13 09:15:29 by aymoulou #+# #+# */
/* Updated: 2021/08/31 13:31:12 by aymoulou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lsapply(t_list *l, t_list *s, void *(*f)(void *), void (*d)(void *))
{
if (l)
{
s = ft_lstnew(f(l->content));
if (!s)
{
ft_lstclear(&s, d);
return (NULL);
}
s->next = ft_lsapply(l->next, s->next, f, d);
}
return (s);
}
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *start;
start = NULL;
start = ft_lsapply(lst, start, f, del);
return (start);
}