ft_lstdelone: initial implementation
This commit is contained in:
parent
d971555797
commit
3f2e2ae0f2
3 changed files with 60 additions and 3 deletions
5
Makefile
5
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: kcolin <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/14 13:43:59 by kcolin #+# #+# #
|
||||
# Updated: 2024/10/21 13:08:04 by kcolin ### ########.fr #
|
||||
# Updated: 2024/10/21 14:49:31 by kcolin ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -51,7 +51,8 @@ BONUS_SOURCES = ft_lstnew_bonus.c \
|
|||
ft_lstadd_front_bonus.c \
|
||||
ft_lstsize_bonus.c \
|
||||
ft_lstlast_bonus.c \
|
||||
ft_lstadd_back_bonus.c
|
||||
ft_lstadd_back_bonus.c \
|
||||
ft_lstdelone_bonus.c
|
||||
BONUS_OBJECTS = $(BONUS_SOURCES:.c=.o)
|
||||
|
||||
.PHONY: all
|
||||
|
|
|
|||
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);
|
||||
}
|
||||
*/
|
||||
3
libft.h
3
libft.h
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/15 10:11:54 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/21 12:11:28 by kcolin ### ########.fr */
|
||||
/* Updated: 2024/10/21 14:37:19 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -74,5 +74,6 @@ void ft_lstadd_front(t_list **lst, t_list *new);
|
|||
int ft_lstsize(t_list *lst);
|
||||
t_list *ft_lstlast(t_list *lst);
|
||||
void ft_lstadd_back(t_list **lst, t_list *new);
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *));
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue