-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstmap.c
executable file
·37 lines (34 loc) · 1.26 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: dcherend <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/30 16:43:32 by dcherend #+# #+# */
/* Updated: 2018/03/31 20:22:12 by dcherend ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *first;
t_list *another;
if (lst && f)
{
first = f(lst);
another = first;
lst = lst->next;
while (lst)
{
another->next = f(lst);
if (!(another->next))
return (NULL);
another = another->next;
lst = lst->next;
}
another->next = NULL;
return (first);
}
return (NULL);
}