added a few lst functions for fillit
This commit is contained in:
parent
f74b6a0410
commit
a8da79f3c1
5 changed files with 52 additions and 5 deletions
|
|
@ -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
libft/ft_lsteadd.c
Normal file
16
libft/ft_lsteadd.c
Normal 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
libft/ft_lstlast.c
Normal file
8
libft/ft_lstlast.c
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
while (lst->next)
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
||||
23
libft/ft_lstnadd.c
Normal file
23
libft/ft_lstnadd.c
Normal 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;
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue