-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstmap.c
executable file
·40 lines (36 loc) · 1.33 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
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ngouy <ngouy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/11 17:57:02 by ngouy #+# #+# */
/* Updated: 2015/11/04 16:15:05 by ngouy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** Create a copy of the list,
** apply the fonction f() for each link of the new list,
** return the new list.
*/
#include "libft.h"
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *tmp;
t_list *tmp2;
t_list *ret;
ret = NULL;
if (!lst || !f)
return (ret = malloc(0));
tmp = lst;
ft_lstadd(&ret, f(tmp));
tmp = tmp->next;
tmp2 = ret;
while (tmp)
{
ft_lstaddend(&tmp2, f(tmp));
tmp = tmp->next;
}
return (ret);
}