-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstmap.c
38 lines (35 loc) · 1.42 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
/* ************************************************************************** */
/* LE - / */
/* / */
/* ft_lstmap.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: cgarrot <[email protected]> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/10/14 17:51:44 by cgarrot #+# ## ## #+# */
/* Updated: 2018/10/14 17:53:41 by cgarrot ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *result;
t_list *head;
t_list *elem;
if (!lst || !f)
return (NULL);
elem = f(lst);
if (!(result = ft_lstnew(elem->content, elem->content_size)))
return (NULL);
lst = lst->next;
head = result;
while (lst)
{
elem = f(lst);
if (!(result->next = ft_lstnew(elem->content, elem->content_size)))
return (NULL);
result = result->next;
lst = lst->next;
}
return (head);
}