-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstmap.c
More file actions
41 lines (38 loc) · 1.4 KB
/
ft_lstmap.c
File metadata and controls
41 lines (38 loc) · 1.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jagarcia <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/16 05:16:58 by jagarcia #+# #+# */
/* Updated: 2017/11/16 07:52:01 by jagarcia ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *newlist;
t_list *tmp;
t_list *cpynewlist;
if (lst)
{
tmp = (*f)(lst);
newlist = ft_lstnew(tmp->content, tmp->content_size);
if (!newlist)
return (NULL);
cpynewlist = newlist;
while (lst->next)
{
lst = lst->next;
tmp = (*f)(lst);
cpynewlist->next = ft_lstnew(tmp->content, tmp->content_size);
if (!cpynewlist->next)
return (NULL);
cpynewlist = cpynewlist->next;
}
}
else
return (NULL);
return (newlist);
}