ft_lstadd_front: initial implementation

This commit is contained in:
Khaïs COLIN 2024-10-21 11:40:47 +02:00
parent 8777bfc3c3
commit a620c3606d
3 changed files with 47 additions and 2 deletions

View file

@ -6,7 +6,7 @@
# By: kcolin <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/10/14 13:43:59 by kcolin #+# #+# #
# Updated: 2024/10/21 11:19:20 by kcolin ### ########.fr #
# Updated: 2024/10/21 11:39:38 by kcolin ### ########.fr #
# #
# **************************************************************************** #
@ -47,7 +47,8 @@ SOURCES = ft_isalpha.c \
ft_putendl_fd.c \
ft_putnbr_fd.c
OBJECTS = $(SOURCES:.c=.o)
BONUS_SOURCES = ft_lstnew_bonus.c
BONUS_SOURCES = ft_lstnew_bonus.c \
ft_lstadd_front_bonus.c
BONUS_OBJECTS = $(BONUS_SOURCES:.c=.o)
.PHONY: all

43
ft_lstadd_front_bonus.c Normal file
View file

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/21 11:30:38 by kcolin #+# #+# */
/* Updated: 2024/10/21 11:38:08 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_front(t_list **lst, t_list *new)
{
new->next = *lst;
*lst = new;
}
/*
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
t_list *list;
t_list *new;
list = ft_lstnew("Hello There!");
printf("current:\t%p\n", list);
printf("content:\t%s\n", (char *)list->content);
printf("next:\t\t%p\n", list->next);
new = ft_lstnew("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);
free(list->next);
free(list);
return (0);
}
*/

View file

@ -70,5 +70,6 @@ typedef struct s_list
} t_list;
t_list *ft_lstnew(void *content);
void ft_lstadd_front(t_list **lst, t_list *new);
#endif