36 lines
1.2 KiB
C
36 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_lstmap.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2018/11/14 21:11:20 by hulamy #+# #+# */
|
|
/* Updated: 2018/11/16 14:01:23 by hulamy ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
|
|
{
|
|
t_list *new;
|
|
t_list *tmp;
|
|
|
|
if (!lst)
|
|
return (NULL);
|
|
tmp = f(lst);
|
|
new = tmp;
|
|
while (lst->next)
|
|
{
|
|
lst = lst->next;
|
|
if (!(tmp->next = f(lst)))
|
|
{
|
|
free(tmp->next);
|
|
return (NULL);
|
|
}
|
|
tmp = tmp->next;
|
|
}
|
|
return (new);
|
|
}
|