diff --git a/srcd/bonus/ft_lstclear.c b/srcd/bonus/ft_lstclear.c index b66cc39..a28d366 100644 --- a/srcd/bonus/ft_lstclear.c +++ b/srcd/bonus/ft_lstclear.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/25 14:13:30 by hulamy #+# #+# */ -/* Updated: 2019/11/25 14:31:30 by hulamy ### ########.fr */ +/* Updated: 2019/11/28 17:06:48 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */ @@ -96,7 +96,12 @@ void ft_lstclear(t_list **lst, void (*del)(void *)) { - if ((*lst)->next) - ft_lstclear(&(*lst)->next, del); - ft_lstdelone(*lst, del); + t_list *next; + + while (*lst != NULL) + { + next = (*lst)->next; + ft_lstdelone(*lst, del); + *lst = next; + } } diff --git a/srcs/ft_lstclear.c b/srcs/ft_lstclear.c index b66cc39..d151381 100644 --- a/srcs/ft_lstclear.c +++ b/srcs/ft_lstclear.c @@ -1,15 +1,3 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstclear.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: hulamy +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/25 14:13:30 by hulamy #+# #+# */ -/* Updated: 2019/11/25 14:31:30 by hulamy ### ########.fr */ -/* */ -/* ************************************************************************** */ - /* ** delete and free an element of the list and all the followings */ @@ -96,7 +84,12 @@ void ft_lstclear(t_list **lst, void (*del)(void *)) { - if ((*lst)->next) - ft_lstclear(&(*lst)->next, del); - ft_lstdelone(*lst, del); + t_list *next; + + while (*lst != NULL) + { + next = (*lst)->next; + ft_lstdelone(*lst, del); + *lst = next; + } } diff --git a/srcs/ft_lstdelone.c b/srcs/ft_lstdelone.c index 3ff3259..9ce8910 100644 --- a/srcs/ft_lstdelone.c +++ b/srcs/ft_lstdelone.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/25 14:14:03 by hulamy #+# #+# */ -/* Updated: 2019/11/25 14:35:53 by hulamy ### ########.fr */ +/* Updated: 2019/11/28 16:56:40 by hulamy ### ########.fr */ /* */ /* ************************************************************************** */