ft_lstdelone: initial implementation
This commit is contained in:
parent
d971555797
commit
3f2e2ae0f2
3 changed files with 60 additions and 3 deletions
55
ft_lstdelone_bonus.c
Normal file
55
ft_lstdelone_bonus.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/21 14:37:36 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/21 14:48:00 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
(*del)(lst->content);
|
||||
free(lst);
|
||||
}
|
||||
|
||||
/*
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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 last...");
|
||||
ft_lstdelone(ft_lstlast(list), &free);
|
||||
list->next = NULL;
|
||||
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));
|
||||
free(list->content);
|
||||
free(list);
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue