Libft
 
Loading...
Searching...
No Matches
Linked lists functions

LST functions. More...

Functions

t_listft_lstnew (void *content)
 Allocate (with malloc(3)) and return a new element. The variable member 'content' is initialized with the value of the parameter 'content'. The variable 'next' is initialized to NULL.
 
void ft_lstadd_front (t_list **lst, t_list *new)
 Adds the element ’new’ at the start of the list.
 
int ft_lstsize (t_list *lst)
 Count the number of elements in a list.
 
t_listft_lstlast (t_list *lst)
 Returns the last element of the list.
 
void ft_lstadd_back (t_list **lst, t_list *new)
 Adds the element ’new’ at the end of the list.
 
void ft_lstdelone (t_list *lst, void(*del)(void *))
 Free the memory of the element passed as a parameter using the function 'del' and free(3). The memory of next must not be freed.
 
void ft_lstclear (t_list **lst, void(*del)(void *))
 Deletes and free the memory of the element passed as a parameter, and all the elements that follow, using 'del' and free(3) Finally, the initial pointer must be set to NULL.
 
void ft_lstiter (t_list *lst, void(*f)(void *))
 Iterate on the linked list 'lst' and apply the function 'f' on the content of each element.
 
t_listft_lstmap (t_list *lst, void *(*f)(void *), void(*del)(void *))
 Iterated on the linked list 'list' and apply the function 'f' on the content of each element. Create a new list resulting from the successive applications of 'f'. The function 'del' is there to destroy the content of an element if necessary.
 
void ft_swap_nodes (t_list **start, t_list *lst1, t_list *lst2)
 Swap two nodes in a linked list (swap nodes, not content)
 

Detailed Description

LST functions.

Function Documentation

◆ ft_lstadd_back()

void ft_lstadd_back ( t_list ** lst,
t_list * new )

Adds the element ’new’ at the end of the list.

Parameters
lsthead of the linked list
newnew node to add
Here is the call graph for this function:

◆ ft_lstadd_front()

void ft_lstadd_front ( t_list ** lst,
t_list * new )

Adds the element ’new’ at the start of the list.

Parameters
lsthead of the linked list
newnew node to add

◆ ft_lstclear()

void ft_lstclear ( t_list ** lst,
void(* del )(void *) )

Deletes and free the memory of the element passed as a parameter, and all the elements that follow, using 'del' and free(3) Finally, the initial pointer must be set to NULL.

Parameters
lsthead of the linked list
delfunction to apply to delete all the content of the element
Here is the call graph for this function:

◆ ft_lstdelone()

void ft_lstdelone ( t_list * lst,
void(* del )(void *) )

Free the memory of the element passed as a parameter using the function 'del' and free(3). The memory of next must not be freed.

Parameters
lsthead of the linked list
delfunction to apply to delete all the content of the element

◆ ft_lstiter()

void ft_lstiter ( t_list * lst,
void(* )(void *) )

Iterate on the linked list 'lst' and apply the function 'f' on the content of each element.

Parameters
lsthead of the linked list
ffunction to apply to the content of each element

◆ ft_lstlast()

t_list * ft_lstlast ( t_list * lst)

Returns the last element of the list.

Parameters
lsthead of the linked list
Returns
t_list* last element of the list

◆ ft_lstmap()

t_list * ft_lstmap ( t_list * lst,
void *(* )(void *),
void(* del )(void *) )

Iterated on the linked list 'list' and apply the function 'f' on the content of each element. Create a new list resulting from the successive applications of 'f'. The function 'del' is there to destroy the content of an element if necessary.

Parameters
lsthead of the linked list
ffunction to apply to the content of each element
delfunction to apply to delete all the content of the element
Returns
t_list* new list modified by f
Here is the call graph for this function:

◆ ft_lstnew()

t_list * ft_lstnew ( void * content)

Allocate (with malloc(3)) and return a new element. The variable member 'content' is initialized with the value of the parameter 'content'. The variable 'next' is initialized to NULL.

Parameters
contentcontent to add to the new element
Returns
t_list* new element

◆ ft_lstsize()

int ft_lstsize ( t_list * lst)

Count the number of elements in a list.

Parameters
lstlist to count
Returns
int number of elements in the list

◆ ft_swap_nodes()

void ft_swap_nodes ( t_list ** start,
t_list * lst1,
t_list * lst2 )

Swap two nodes in a linked list (swap nodes, not content)

Parameters
starthead of the linked list
lst1First node to swap
lst2Second node to swap