diff --git a/libft/ft_lstadd.c b/libft/ft_lstadd.c index 068fdaf3..e9042877 100644 --- a/libft/ft_lstadd.c +++ b/libft/ft_lstadd.c @@ -2,9 +2,6 @@ void ft_lstadd(t_list **alst, t_list *new) { - if (new) - { - new->next = *alst; - *alst = new; - } + new->next = *alst; + *alst = new; } diff --git a/libft/ft_lsteadd.c b/libft/ft_lsteadd.c new file mode 100644 index 00000000..3b9e391f --- /dev/null +++ b/libft/ft_lsteadd.c @@ -0,0 +1,16 @@ +#include "libft.h" + +void ft_lsteadd(t_list **alst, t_list *new) +{ + t_list *lst; + + lst = *alst; + if (lst) + { + while (lst->next) + lst = lst->next; + lst->next = new; + } + else + *alst = new; +} diff --git a/libft/ft_lstlast.c b/libft/ft_lstlast.c new file mode 100644 index 00000000..5115a1fe --- /dev/null +++ b/libft/ft_lstlast.c @@ -0,0 +1,8 @@ +#include "libft.h" + +t_list *ft_lstlast(t_list *lst) +{ + while (lst->next) + lst = lst->next; + return (lst); +} diff --git a/libft/ft_lstnadd.c b/libft/ft_lstnadd.c new file mode 100644 index 00000000..7db6c631 --- /dev/null +++ b/libft/ft_lstnadd.c @@ -0,0 +1,23 @@ +#include "libft.h" + +void ft_lstnadd(t_list **alst, t_list *new, int n) +{ + t_list *lst; + int i; + + lst = *alst; + if (lst) + { + i = 0; + while (lst->next && i < n) + { + lst = lst->next; + i++; + } + while (lst->next) + lst = lst->next; + lst->next = new; + } + else + *alst = new; +} diff --git a/libft/libft.h b/libft/libft.h index 87ba3de0..c2e95ece 100644 --- a/libft/libft.h +++ b/libft/libft.h @@ -76,5 +76,8 @@ void ft_putnbr_fd(int n, int fd); t_list *ft_lstnew(void const *content, size_t content_size); void ft_lstadd(t_list **alst, t_list *new); +void ft_lsteadd(t_list **alst, t_list *new); +void ft_lstnadd(t_list **alst, t_list *new, int n); +t_list *ft_lstlast(t_list *lst) #endif