diff --git a/srcs/bonus/a.out b/srcs/bonus/a.out index a1ab014..fbebddb 100755 Binary files a/srcs/bonus/a.out and b/srcs/bonus/a.out differ diff --git a/srcs/bonus/ft_lstiter.c b/srcs/bonus/ft_lstiter.c new file mode 100644 index 0000000..9da910e --- /dev/null +++ b/srcs/bonus/ft_lstiter.c @@ -0,0 +1,88 @@ +/* +** go through all elements of the list and apply the function f to each of them +*/ + +/* +** #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_lstiter(t_list *lst, void (*f)(void*)); +** +** void to_uppercase(void *element) +** { +** // *(char*)(((t_list*)element)->content) -= 32; +** // or : +** t_list *tmp; +** +** tmp = (t_list*)element; +** *(char*)(tmp->content) -= 32; +** } +** int main(void) +** { +** t_list *toto; +** void to_uppercase(void*); +** +** toto = ft_lstnew("a"); +** toto->next = ft_lstnew("b"); +** toto->next->next = ft_lstnew("c"); +** 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)); +** printf("---------------------------\n"); +** ft_lstiter(toto, to_uppercase); +** 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_lstiter(t_list *lst, void (*f)(void *)) +{ + if (!lst) + return ; + if (lst->next) + ft_lstiter(lst->next, f); + f(lst); +} diff --git a/srcs/bonus/lstclear.c b/srcs/bonus/lstclear.c index bbe792d..11161dd 100644 --- a/srcs/bonus/lstclear.c +++ b/srcs/bonus/lstclear.c @@ -1,15 +1,3 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstdel.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: hulamy +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2018/11/14 21:10:49 by hulamy #+# #+# */ -/* Updated: 2018/11/16 13:59:10 by hulamy ### ########.fr */ -/* */ -/* ************************************************************************** */ - #include "libft.h" void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) @@ -18,3 +6,4 @@ void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) ft_lstdel(&(*alst)->next, del); ft_lstdelone(alst, del); } + 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/lstiter.c b/srcs/bonus/lstiter.c deleted file mode 100644 index 0f791be..0000000 --- a/srcs/bonus/lstiter.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstiter.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: hulamy +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2018/11/14 21:11:14 by hulamy #+# #+# */ -/* Updated: 2018/11/16 14:01:10 by hulamy ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstiter(t_list *lst, void (*f)(t_list *elem)) -{ - if (!lst) - return ; - if (lst->next) - ft_lstiter(lst->next, f); - f(lst); -}