diff --git a/.Makefile.swn b/.Makefile.swn index e0cde22..f1d6f70 100644 Binary files a/.Makefile.swn and b/.Makefile.swn differ diff --git a/OLDincludes/.libft.h.swp b/OLDincludes/.libft.h.swp deleted file mode 100644 index 86b3dad..0000000 Binary files a/OLDincludes/.libft.h.swp and /dev/null differ diff --git a/srcs/bonus/a.out b/srcs/bonus/a.out index 2291bc9..6a73564 100755 Binary files a/srcs/bonus/a.out and b/srcs/bonus/a.out differ diff --git a/srcs/bonus/ft_lstadd_back.c b/srcs/bonus/ft_lstadd_back.c index bfaf6ee..99117c2 100644 --- a/srcs/bonus/ft_lstadd_back.c +++ b/srcs/bonus/ft_lstadd_back.c @@ -1,13 +1,98 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_back.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: hulamy +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/11/20 15:14:22 by hulamy #+# #+# */ -/* Updated: 2019/11/20 15:14:35 by hulamy ### ########.fr */ -/* */ -/* ************************************************************************** */ +/* +** add an element to the end of a list +** or first if list has no element so far +*/ + +/* +** #include +** +** typedef struct s_list +** { +** void *content; +** struct s_list *next; +** } t_list; +** +** void *ft_memcpy(void *dst, const void *src, size_t n) +** { +** size_t i; +** char *ptr; +** char *ptr2; +** +** ptr = (char *)dst; +** ptr2 = (char *)src; +** i = -1; +** while (++i < n) +** ptr[i] = ptr2[i]; +** return (dst); +** } +** +** t_list *ft_lstnew(void *content) +** { +** t_list *lst; +** +** if (!(lst = (t_list *)malloc(sizeof(*lst)))) +** return (NULL); +** if (!content) +** lst->content = NULL; +** else +** { +** if (!(lst->content = malloc(sizeof(content)))) +** return (NULL); +** ft_memcpy(lst->content, content, sizeof(content)); +** } +** lst->next = NULL; +** return (lst); +** } +** +** void ft_lstadd_back(t_list **alst, t_list *new); +** +** int main(void) +** { +** char tresor; +** char matos; +** char friends; +** t_list *toto; +** t_list *tmp; +** +** tresor = 'a'; +** matos = 'b'; +** friends = 'c'; +** toto = ft_lstnew(&tresor); +** printf("toto->data :%c\n",*(char*)(toto->content)); +** tmp = ft_lstnew(&matos); +** ft_lstadd_back(&toto, tmp); +** printf("----------------------\n"); +** printf("toto->data :%c\n",*(char*)(toto->content)); +** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content)); +** tmp = ft_lstnew(&friends); +** ft_lstadd_back(&toto, tmp); +** printf("----------------------\n"); +** printf("toto->data :%c\n",*(char*)(toto->content)); +** printf("toto->nxt->data :%c\n",*(char*)(toto->next->content)); +** printf("toto->nxt->nxt->data:%c\n",*(char*)(toto->next->next->content)); +** printf("toto->nxt->nxt->nxt :%s\n",(char*)(toto->next->next->next)); +** return (0); +** } +*/ #include "libft.h" + +void ft_lstadd_back(t_list **alst, t_list *new) +{ + t_list *tmp; + + if (alst) + { + tmp = *alst; + if (!tmp) + *alst = new; + else + { + while (tmp->next) + tmp = tmp->next; + tmp->next = new; + } + new->content = NULL; + } +} + diff --git a/srcs/bonus/ft_lstdel.c b/srcs/bonus/lstclear.c similarity index 100% rename from srcs/bonus/ft_lstdel.c rename to srcs/bonus/lstclear.c diff --git a/srcs/bonus/ft_lstdelone.c b/srcs/bonus/lstdelone.c similarity index 100% rename from srcs/bonus/ft_lstdelone.c rename to srcs/bonus/lstdelone.c diff --git a/srcs/bonus/ft_lstiter.c b/srcs/bonus/lstiter.c similarity index 100% rename from srcs/bonus/ft_lstiter.c rename to srcs/bonus/lstiter.c diff --git a/srcs/bonus/ft_lstmap.c b/srcs/bonus/lstmap.c similarity index 100% rename from srcs/bonus/ft_lstmap.c rename to srcs/bonus/lstmap.c