-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstmap.c
executable file
·39 lines (36 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
39
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tseguier <tseguier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2013/11/27 18:55:55 by tseguier #+# #+# */
/* Updated: 2014/03/27 18:39:05 by jcoignet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *maplst;
t_list *maplst_iter;
t_list *mapelem;
if (!f || !lst)
return (NULL);
mapelem = (*f)(lst);
maplst = ft_lstnew(mapelem->content, mapelem->content_size);
if (!maplst)
return (NULL);
maplst_iter = maplst;
lst = lst->next;
while (lst)
{
mapelem = (*f)(lst);
maplst_iter->next = ft_lstnew(mapelem->content, mapelem->content_size);
if (!maplst_iter->next)
return (NULL);
maplst_iter = maplst_iter->next;
lst = lst->next;
}
return (maplst);
}