/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_lstclear_bonus.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/21 14:53:58 by kcolin #+# #+# */ /* Updated: 2024/10/21 15:17:38 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" void ft_lstclear(t_list **lst, void (*del)(void *)) { if (*lst == NULL) return ; if ((*lst)->next != NULL) { ft_lstclear(&((*lst)->next), del); ft_lstdelone(*lst, del); *lst = NULL; } else { ft_lstdelone(*lst, del); *lst = NULL; } } /* #include #include int main(void) { t_list *list; t_list *new; list = ft_lstnew(ft_strdup("Hello There!")); printf("current:\t%p\n", list); printf("content:\t%s\n", (char *)list->content); printf("next:\t\t%p\n", list->next); printf("length:\t%d\n", ft_lstsize(list)); new = ft_lstnew(ft_strdup("New Element!")); ft_lstadd_front(&list, new); printf("current:\t%p\n", list); printf("content:\t%s\n", (char *)list->content); printf("next:\t\t%p\n", list->next); printf("length:\t%d\n", ft_lstsize(list)); printf("last:\t\t%p\n", ft_lstlast(list)); printf("=> deleting...\n"); ft_lstclear(&list, &free); ft_lstclear(&list, &free); printf("current:\t%p\n", list); return (0); } */