diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-15 10:04:09 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-15 10:04:09 +0100 |
| commit | 1e9b077e0d9f3c50d7d518bf6ea7f08e7f5ec590 (patch) | |
| tree | 21d906cd9f96c58af572ce3bb6784d1d8fca18d2 /src/lst | |
| parent | 49ad59b0e773e92e93fb69ede889c781ca53e680 (diff) | |
| download | libft-1e9b077e0d9f3c50d7d518bf6ea7f08e7f5ec590.tar.gz libft-1e9b077e0d9f3c50d7d518bf6ea7f08e7f5ec590.tar.bz2 libft-1e9b077e0d9f3c50d7d518bf6ea7f08e7f5ec590.zip | |
splited src in category, more generic makefile
Diffstat (limited to 'src/lst')
| -rw-r--r-- | src/lst/ft_lstadd_back.c | 25 | ||||
| -rw-r--r-- | src/lst/ft_lstadd_front.c | 21 | ||||
| -rw-r--r-- | src/lst/ft_lstclear.c | 24 | ||||
| -rw-r--r-- | src/lst/ft_lstdelone.c | 22 | ||||
| -rw-r--r-- | src/lst/ft_lstiter.c | 24 | ||||
| -rw-r--r-- | src/lst/ft_lstlast.c | 22 | ||||
| -rw-r--r-- | src/lst/ft_lstmap.c | 48 | ||||
| -rw-r--r-- | src/lst/ft_lstnew.c | 24 | ||||
| -rw-r--r-- | src/lst/ft_lstpop_front.c | 26 | ||||
| -rw-r--r-- | src/lst/ft_lstsize.c | 26 |
10 files changed, 262 insertions, 0 deletions
diff --git a/src/lst/ft_lstadd_back.c b/src/lst/ft_lstadd_back.c new file mode 100644 index 0000000..01eb00c --- /dev/null +++ b/src/lst/ft_lstadd_back.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_back_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:02:03 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:01:26 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_back(t_list **alst, t_list *new) +{ + if (alst == NULL) + return ; + if (*alst == NULL) + { + *alst = new; + return ; + } + ft_lstlast(*alst)->next = new; +} diff --git a/src/lst/ft_lstadd_front.c b/src/lst/ft_lstadd_front.c new file mode 100644 index 0000000..282b0b4 --- /dev/null +++ b/src/lst/ft_lstadd_front.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:02:25 by cacharle #+# #+# */ +/* Updated: 2019/10/18 12:16:06 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_front(t_list **alst, t_list *new) +{ + if (alst == NULL || new == NULL) + return ; + new->next = *alst; + *alst = new; +} diff --git a/src/lst/ft_lstclear.c b/src/lst/ft_lstclear.c new file mode 100644 index 0000000..ee1d9e5 --- /dev/null +++ b/src/lst/ft_lstclear.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:02:39 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:02:37 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstclear(t_list **lst, void (*del)(void *)) +{ + if (lst == NULL) + return ; + if (*lst == NULL) + return ; + ft_lstclear(&((*lst)->next), del); + ft_lstdelone(*lst, del); + *lst = NULL; +} diff --git a/src/lst/ft_lstdelone.c b/src/lst/ft_lstdelone.c new file mode 100644 index 0000000..30cec69 --- /dev/null +++ b/src/lst/ft_lstdelone.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:03:02 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:02:31 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstdelone(t_list *lst, void (*del)(void *)) +{ + if (lst == NULL) + return ; + if (del != NULL) + (*del)(lst->content); + free(lst); +} diff --git a/src/lst/ft_lstiter.c b/src/lst/ft_lstiter.c new file mode 100644 index 0000000..282e0fa --- /dev/null +++ b/src/lst/ft_lstiter.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:03:22 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:01:39 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstiter(t_list *lst, void (*f)(void *)) +{ + if (f == NULL) + return ; + while (lst != NULL) + { + (*f)(lst->content); + lst = lst->next; + } +} diff --git a/src/lst/ft_lstlast.c b/src/lst/ft_lstlast.c new file mode 100644 index 0000000..247f4da --- /dev/null +++ b/src/lst/ft_lstlast.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:03:40 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:02:26 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstlast(t_list *lst) +{ + if (lst == NULL) + return (NULL); + while (lst->next != NULL) + lst = lst->next; + return (lst); +} diff --git a/src/lst/ft_lstmap.c b/src/lst/ft_lstmap.c new file mode 100644 index 0000000..c623d6f --- /dev/null +++ b/src/lst/ft_lstmap.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:03:57 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:01:31 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) +{ + t_list *mapped; + t_list *tmp; + + if (lst == NULL || f == NULL) + return (NULL); + mapped = NULL; + while (lst != NULL) + { + if ((tmp = ft_lstnew((*f)(lst->content))) == NULL) + { + ft_lstclear(&mapped, del); + return (NULL); + } + ft_lstadd_back(&mapped, tmp); + lst = lst->next; + } + return (mapped); +} + +/* +** Rest in peace, my beautiful recursion. +** +** t_list *tmp; +** +** if (lst == NULL) +** return (NULL); +** if ((tmp = ft_lstnew(lst->content)) == NULL) +** return (NULL); +** tmp->content = (*f)(tmp->content); +** tmp->next = ft_lstmap(lst->next, f); +** return (tmp); +*/ diff --git a/src/lst/ft_lstnew.c b/src/lst/ft_lstnew.c new file mode 100644 index 0000000..ea10e4d --- /dev/null +++ b/src/lst/ft_lstnew.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:01:16 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:01:35 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstnew(void const *content) +{ + t_list *elem; + + if ((elem = (t_list*)malloc(sizeof(t_list))) == NULL) + return (NULL); + elem->content = (void*)content; + elem->next = NULL; + return (elem); +} diff --git a/src/lst/ft_lstpop_front.c b/src/lst/ft_lstpop_front.c new file mode 100644 index 0000000..f81315a --- /dev/null +++ b/src/lst/ft_lstpop_front.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstpop_front_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/25 03:32:51 by cacharle #+# #+# */ +/* Updated: 2019/10/25 03:35:58 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> +#include "libft.h" + +void ft_lstpop_front(t_list **lst, void (*del)(void *)) +{ + t_list *tmp; + + if (lst == NULL || *lst == NULL) + return ; + tmp = (*lst)->next; + del((*lst)->content); + free(*lst); + *lst = tmp; +} diff --git a/src/lst/ft_lstsize.c b/src/lst/ft_lstsize.c new file mode 100644 index 0000000..b9d65d2 --- /dev/null +++ b/src/lst/ft_lstsize.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/09 09:04:28 by cacharle #+# #+# */ +/* Updated: 2019/11/20 04:01:44 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_lstsize(t_list *lst) +{ + int counter; + + counter = 0; + while (lst != NULL) + { + counter++; + lst = lst->next; + } + return (counter); +} |
