aboutsummaryrefslogtreecommitdiffstats
path: root/inc/libft.h
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-02-21 17:33:28 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-02-21 17:33:28 +0100
commit7a34b3d412f5022d4ce25d84ec7fb4002b1fb5db (patch)
tree9546a74914e750e747adb2d9adcd7b67f96adf24 /inc/libft.h
parent9bb8e5cd549eca189ce183f40f771c2a614ea8f6 (diff)
downloadLibft-7a34b3d412f5022d4ce25d84ec7fb4002b1fb5db.tar.gz
Libft-7a34b3d412f5022d4ce25d84ec7fb4002b1fb5db.zip
Implement libft Part 3 (linked lists) with tests
Add t_list struct and 9 linked list functions: ft_lstnew, ft_lstadd_front, ft_lstsize, ft_lstlast, ft_lstadd_back, ft_lstdelone, ft_lstclear, ft_lstiter, ft_lstmap.
Diffstat (limited to 'inc/libft.h')
-rw-r--r--inc/libft.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/inc/libft.h b/inc/libft.h
index 05a5ae9..48b2c0b 100644
--- a/inc/libft.h
+++ b/inc/libft.h
@@ -135,4 +135,33 @@ void ft_putendl_fd (char *s, int fd);
/** @brief Write integer @p n in decimal to @p fd. */
void ft_putnbr_fd (int n, int fd);
+/* ======================================
+ * Linked list
+ * ====================================== */
+
+typedef struct s_list
+{
+ void *content; /**< Node payload (owned by the caller). */
+ struct s_list *next; /**< Next node, or NULL for the tail. */
+} t_list;
+
+/** @brief Allocate a new list node with @p content; next is NULL. */
+t_list *ft_lstnew (void *content);
+/** @brief Prepend @p new to the list pointed to by @p lst. */
+void ft_lstadd_front (t_list **lst, t_list *new);
+/** @brief Count the number of nodes in @p lst. */
+int ft_lstsize (t_list *lst);
+/** @brief Return the last node of @p lst. */
+t_list *ft_lstlast (t_list *lst);
+/** @brief Append @p new to the end of the list pointed to by @p lst. */
+void ft_lstadd_back (t_list **lst, t_list *new);
+/** @brief Delete one node's content with @p del and free the node. */
+void ft_lstdelone (t_list *lst, void (*del) (void *));
+/** @brief Delete and free all nodes in @p lst using @p del; set *lst=NULL. */
+void ft_lstclear (t_list **lst, void (*del) (void *));
+/** @brief Apply @p f to the content of each node in @p lst. */
+void ft_lstiter (t_list *lst, void (*f) (void *));
+/** @brief Map @p f over @p lst, creating a new list; use @p del on failure. */
+t_list *ft_lstmap (t_list *lst, void *(*f) (void *), void (*del) (void *));
+
#endif