Libft
42 Libft library documentation
Loading...
Searching...
No Matches
ft_lstadd_back.c File Reference
+ Include dependency graph for ft_lstadd_back.c:

Go to the source code of this file.

Functions

void ft_lstadd_back (t_list **lst, t_list *new)
 Adds a new element to the end of a linked list. This function takes a pointer to the first element of a linked list and a new element, then adds the new element to the end of the list. If the list is empty, the new element becomes the first element.
 

Function Documentation

◆ ft_lstadd_back()

void ft_lstadd_back ( t_list **  lst,
t_list new 
)

Adds a new element to the end of a linked list. This function takes a pointer to the first element of a linked list and a new element, then adds the new element to the end of the list. If the list is empty, the new element becomes the first element.

Parameters
lstA pointer to the pointer to the first element of the list.
newThe new element to add to the end of the list.

Definition at line 25 of file ft_lstadd_back.c.

26{
27 t_list *last;
28
29 if (!lst || !new)
30 return ;
31 if (!*lst)
32 {
33 *lst = new;
34 return ;
35 }
36 last = ft_lstlast(*lst);
37 last->next = new;
38}
t_list * ft_lstlast(t_list *lst)
Returns the last element of a linked list. This function takes a linked list and returns a pointer to...
Definition ft_lstlast.c:23
Definition types.h:4
struct s_list * next
Definition types.h:6

References ft_lstlast(), and s_list::next.

Referenced by ft_lstmap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: