-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstclear_bonus.c
29 lines (25 loc) · 1.35 KB
/
ft_lstclear_bonus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dolvin17 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/03 19:41:34 by ghuertas #+# #+# */
/* Updated: 2022/04/22 01:11:21 by dolvin17 ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* elimina y libera todos los elementos de la lista */
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *pos;
if (!lst)//si la lista no existe
return ; //no hago nada.
while (*lst != NULL) //mientras mi nodo actual sea distinto de null.
{
pos = (*lst)->next; // guardo la ref DE POS en el siguiente nodo (NEXT)
ft_lstdelone(*lst, del); //elimino el nodo y libero la memoria.
*lst = pos; //repito la operacion hasta salir del bucle.
}
}