ft_lstaddend

This commit is contained in:
Tanguy MAZE
2018-04-19 14:41:21 +02:00
parent baf67e49a6
commit 5703ae8db7
9 changed files with 66 additions and 10 deletions

31
ft_lstaddend.c Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstaddend.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/17 20:55:26 by tmaze #+# #+# */
/* Updated: 2018/04/19 14:32:44 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstaddend(t_list **alst, t_list *new)
{
t_list **tmp;
if (new == NULL)
return (NULL);
if (ft_lstsize(*alst) == 0)
ft_lstadd(alst, new);
else if (ft_lstsize(*alst) > 0)
{
if ((tmp = (t_list**)malloc(sizeof(t_list*))) == NULL)
return (NULL);
*tmp = ft_lstgetlast(*alst);
ft_lstadd(&(*tmp)->next, new);
}
return (*alst);
}