added a few lst functions for fillit

This commit is contained in:
Jack Halford 2016-09-05 12:50:52 +02:00
parent 65129411e2
commit 70ca753440
5 changed files with 52 additions and 5 deletions

View file

@ -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;
}

16
libftasm/ft_lsteadd.c Normal file
View file

@ -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;
}

8
libftasm/ft_lstlast.c Normal file
View file

@ -0,0 +1,8 @@
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
while (lst->next)
lst = lst->next;
return (lst);
}

23
libftasm/ft_lstnadd.c Normal file
View file

@ -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;
}

View file

@ -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