-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstmap.c
37 lines (34 loc) · 1.29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tlevaufr <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/19 22:04:43 by tlevaufr #+# #+# */
/* Updated: 2017/12/20 16:07:23 by tlevaufr ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
size_t i;
t_list *new_lst;
t_list **new_alst;
i = 0;
while (lst)
{
if (i == 0)
{
new_lst = f(ft_lstnew(lst->content, lst->content_size));
new_alst = &new_lst;
new_lst->next = NULL;
}
else
ft_lstad_end(new_alst, f(ft_lstnew(lst->content, \
lst->content_size)));
i++;
lst = lst->next;
}
return (*new_alst);
}