38 lines
1.3 KiB
C
38 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_lstmap.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tchivert <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/04/11 16:08:00 by tchivert #+# #+# */
|
|
/* Updated: 2019/09/04 05:13:28 by tchivert ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
|
|
{
|
|
t_list *new;
|
|
t_list *tmp;
|
|
t_list *start;
|
|
|
|
if (!lst)
|
|
return (NULL);
|
|
tmp = f(lst);
|
|
if (!(new = ft_lstnew(tmp->content, tmp->content_size)))
|
|
return (NULL);
|
|
start = new;
|
|
lst = lst->next;
|
|
while (lst)
|
|
{
|
|
tmp = f(lst);
|
|
if (!(new->next = ft_lstnew(tmp->content, tmp->content_size)))
|
|
return (NULL);
|
|
new = new->next;
|
|
lst = lst->next;
|
|
}
|
|
return (start);
|
|
}
|