-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathft_lstmap.c
More file actions
41 lines (38 loc) · 1.39 KB
/
ft_lstmap.c
File metadata and controls
41 lines (38 loc) · 1.39 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: wbeets <wbeets@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/03/20 11:56:51 by wbeets #+# #+# */
/* Updated: 2015/03/20 11:56:51 by wbeets ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *plst;
t_list *plst2;
t_list *newlist;
t_list *newlist2;
plst = lst;
while (plst)
{
f(plst);
plst = plst->next;
}
newlist = ft_lstnew(lst->content, lst->content_size);
if (newlist == NULL)
return (NULL);
plst2 = newlist;
while (lst->next)
{
newlist2 = ft_lstnew((lst->next)->content, (lst->next)->content_size);
if (newlist2 == NULL)
return (NULL);
newlist->next = newlist2;
lst = lst->next;
}
return (plst2);
}