From e8a7d07f1c99b5ce6210603d88098580af95fb13 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 15 Jan 2020 14:16:36 +0100 Subject: Fix strtol, Added list reverse functions --- src/lst/ft_lstpop_front.c | 5 ++--- src/lst/ft_lstreverse.c | 18 ++++++++++++++++++ src/lst/ft_lstreverse_ret.c | 26 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/lst/ft_lstreverse.c create mode 100644 src/lst/ft_lstreverse_ret.c (limited to 'src/lst') diff --git a/src/lst/ft_lstpop_front.c b/src/lst/ft_lstpop_front.c index f81315a..f59c9b8 100644 --- a/src/lst/ft_lstpop_front.c +++ b/src/lst/ft_lstpop_front.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/25 03:32:51 by cacharle #+# #+# */ -/* Updated: 2019/10/25 03:35:58 by cacharle ### ########.fr */ +/* Updated: 2020/01/15 12:46:28 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,6 @@ void ft_lstpop_front(t_list **lst, void (*del)(void *)) if (lst == NULL || *lst == NULL) return ; tmp = (*lst)->next; - del((*lst)->content); - free(*lst); + ft_lstdelone(*lst, del); *lst = tmp; } diff --git a/src/lst/ft_lstreverse.c b/src/lst/ft_lstreverse.c new file mode 100644 index 0000000..c45a912 --- /dev/null +++ b/src/lst/ft_lstreverse.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstreverse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/15 12:49:14 by cacharle #+# #+# */ +/* Updated: 2020/01/15 12:51:54 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstreverse(t_list **lst) +{ + *lst = ft_lstreverse_ret(*lst); +} diff --git a/src/lst/ft_lstreverse_ret.c b/src/lst/ft_lstreverse_ret.c new file mode 100644 index 0000000..03ae98e --- /dev/null +++ b/src/lst/ft_lstreverse_ret.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstreverse_ret.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/15 12:51:15 by cacharle #+# #+# */ +/* Updated: 2020/01/15 13:36:46 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstreverse_ret(t_list *lst) +{ + t_list *tmp; + if (lst == NULL) + return (NULL); + if (lst->next == NULL) + return (lst); + tmp = ft_lstreverse_ret(lst->next); + lst->next->next = lst; + lst->next = NULL; + return (tmp); +} -- cgit