57 lines
1.7 KiB
C
57 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_lstadd_back_bonus.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/21 12:13:37 by kcolin #+# #+# */
|
|
/* Updated: 2024/10/21 13:29:52 by kcolin ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
#include <stdio.h> // bad
|
|
|
|
void ft_lstadd_back(t_list **lst, t_list *new)
|
|
{
|
|
t_list *back;
|
|
|
|
if (*lst == NULL)
|
|
*lst = new;
|
|
else
|
|
{
|
|
back = ft_lstlast(*lst);
|
|
if (back != NULL)
|
|
back->next = new;
|
|
}
|
|
}
|
|
|
|
/*
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(void)
|
|
{
|
|
t_list *list;
|
|
t_list *new;
|
|
|
|
list = NULL;
|
|
|
|
|
|
ft_lstadd_back(&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);
|
|
printf("length:\t%d\n", ft_lstsize(list));
|
|
new = ft_lstnew("New Element!");
|
|
ft_lstadd_back(&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));
|
|
free(list->next);
|
|
free(list);
|
|
return (0);
|
|
}
|
|
*/
|