|
libft
|
Singly linked list manipulation functions. More...
Files | |
| file | ft_list.c |
| Linked list operations for libft. | |
| file | ft_list.h |
| Linked list for libft. | |
Data Structures | |
| struct | s_list |
Typedefs | |
| typedef struct s_list | t_list |
| Node structure for singly linked list. | |
Functions | |
| void | ft_del (void *content) |
| Deletes content pointer in a list node (utility function). | |
| void | ft_lstadd_back (t_list **lst, t_list *new) |
| Adds a node to the end of a list. | |
| void | ft_lstadd_front (t_list **lst, t_list *new) |
| Adds a node to the front of a list. | |
| void | ft_lstclear (t_list **lst, void(*del)(void *)) |
| Clears an entire list, deleting all its nodes. | |
| void | ft_lstdelone (t_list *lst, void(*del)(void *)) |
| Deletes a single node using a deletion function. | |
| void | ft_lstiter (t_list *lst, void(*f)(void *)) |
| Applies a function to each element of the list. | |
| t_list * | ft_lstlast (t_list *lst) |
| Returns the last node of the list. | |
| t_list * | ft_lstmap (t_list *lst, void *(*f)(void *), void(*del)(void *)) |
| Creates a new list by applying a function to each node. | |
| t_list * | ft_lstnew (void *content) |
| Creates a new list node. | |
| int | ft_lstsize (t_list *lst) |
| Counts the number of nodes in a list. | |
Singly linked list manipulation functions.
This group contains all the functions related to the manipulation of singly linked lists, including creation, insertion, deletion, traversal, and transformation.
This group includes:
These utilities operate on a t_list structure.
| struct s_list |
#include <include/ft_list.h>
Node structure for singly linked list.
Each node contains a generic void* content pointer and a pointer to the next node.
| void ft_del | ( | void * | content | ) |
#include <include/ft_list.h>
Deletes content pointer in a list node (utility function).
Frees the memory pointed to by content.
| content | The content pointer to free. |
This function is typically used as a helper for linked list functions that require a function pointer to properly deallocate memory associated with a node's content. It performs a simple free() operation on the pointer passed.
| content | A pointer to the memory to be freed. |
#include <include/ft_list.h>
Adds a node to the end of a list.
Adds a new node to the end of a linked list.
| lst | The address of the pointer to the first node. |
| new | The node to add to the end. |
If the list is empty, the new node becomes the first node. Otherwise, it is appended to the end of the list.
| lst | A pointer to the pointer to the first node of the list. |
| new | The new node to add to the end of the list. |
#include <include/ft_list.h>
Adds a node to the front of a list.
Adds a new node to the beginning of a linked list.
| lst | The address of the pointer to the first node. |
| new | The new node to add. |
If both the list and the new node are valid, the new node is inserted at the front of the list, and becomes the new head.
| lst | A pointer to the pointer to the first node of the list. |
| new | The new node to add to the beginning of the list. |
| void ft_lstclear | ( | t_list ** | lst, |
| void(*)(void *) | del | ||
| ) |
#include <include/ft_list.h>
Clears an entire list, deleting all its nodes.
Frees all nodes of a list and sets the list pointer to NULL.
| lst | The address of the pointer to the list. |
| del | The function to delete each node's content. |
This function iterates through each node of a linked list, deletes the content of each node using the provided del function, frees the node itself, and finally sets the list pointer to NULL.
| lst | A pointer to the pointer to the first node of the list. |
| del | A pointer to the function used to delete the content of each node. |
| void ft_lstdelone | ( | t_list * | lst, |
| void(*)(void *) | del | ||
| ) |
#include <include/ft_list.h>
Deletes a single node using a deletion function.
Deletes and frees a single list node.
| lst | The node to delete. |
| del | The function to delete the content. |
Frees the memory of the given list node and its content using the del function. The next pointer of the node is not accessed or freed.
| lst | A pointer to the node to delete. |
| del | A pointer to the function used to free the content. |
| void ft_lstiter | ( | t_list * | lst, |
| void(*)(void *) | f | ||
| ) |
#include <include/ft_list.h>
Applies a function to each element of the list.
Iterates over a list and applies a function to each node's content.
| lst | The beginning of the list. |
| f | The function to apply to each node's content. |
This function traverses the given linked list and applies the function f to the content of each node. It does not allocate or free any memory, and it does not modify the list structure.
| lst | Pointer to the first node of the list. |
| f | Function to apply to the content of each node. |
f should not modify the list structure. #include <include/ft_list.h>
Returns the last node of the list.
Retrieves the last node of a linked list.
| lst | The beginning of the list. |
Traverses the linked list starting from the head until the last node (the node with next == NULL) is found.
| lst | Pointer to the head of the list. |
#include <include/ft_list.h>
Creates a new list by applying a function to each node.
Applies a function to each element of a list and builds a new list.
| lst | The original list. |
| f | The transformation function. |
| del | The function to delete content on failure. |
Iterates through the input list lst, applies the function f to the content of each node, and creates a new list with the results. If any allocation fails, the entire new list is cleared using the del function.
| lst | Pointer to the head of the original list. |
| f | Function to apply to the content of each node. |
| del | Function used to delete the content of a node if needed. |
| t_list * ft_lstnew | ( | void * | content | ) |
#include <include/ft_list.h>
Creates a new list node.
Allocates and initializes a new list node.
| content | The content to store in the node. |
Allocates memory for a new t_list node and sets its content to the provided pointer. The next pointer of the new node is set to NULL.
| content | The content to store in the new node. |
| int ft_lstsize | ( | t_list * | lst | ) |
#include <include/ft_list.h>
Counts the number of nodes in a list.
Counts the number of nodes in a linked list.
| lst | The beginning of the list. |
Iterates through the list, counting each node until the end is reached.
| lst | A pointer to the head of the list. |