transforme lstiter sans recursive

This commit is contained in:
Hugo LAMY
2019-11-28 17:21:27 +01:00
parent 1fc3aab389
commit ced3108518
2 changed files with 19 additions and 12 deletions

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */ /* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/25 14:14:11 by hulamy #+# #+# */ /* Created: 2019/11/25 14:14:11 by hulamy #+# #+# */
/* Updated: 2019/11/25 14:34:59 by hulamy ### ########.fr */ /* Updated: 2019/11/28 17:20:38 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -75,9 +75,12 @@
void ft_lstiter(t_list *lst, void (*f)(void *)) void ft_lstiter(t_list *lst, void (*f)(void *))
{ {
if (!lst) if (lst && f)
return ; {
if (lst->next) while (lst)
ft_lstiter(lst->next, f); {
f(lst); f(lst);
lst = lst->next;
}
}
} }

View File

@@ -6,7 +6,7 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */ /* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/25 14:14:11 by hulamy #+# #+# */ /* Created: 2019/11/25 14:14:11 by hulamy #+# #+# */
/* Updated: 2019/11/25 14:34:59 by hulamy ### ########.fr */ /* Updated: 2019/11/28 17:19:34 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -75,9 +75,13 @@
void ft_lstiter(t_list *lst, void (*f)(void *)) void ft_lstiter(t_list *lst, void (*f)(void *))
{ {
if (!lst)
return ; if (lst && f)
if (lst->next) {
ft_lstiter(lst->next, f); while (lst)
f(lst); {
f(lst);
lst = lst->next;
}
{
} }