-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstclear.c
More file actions
37 lines (33 loc) · 1.41 KB
/
ft_lstclear.c
File metadata and controls
37 lines (33 loc) · 1.41 KB
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
30
31
32
33
34
35
36
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: antandre <antandre@student.42barcel> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/26 14:37:14 by antandre #+# #+# */
/* Updated: 2024/06/26 16:02:10 by antandre ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
/*
* Delete and free the given 'lst' node and all consecutive of that node,
* using the function 'del' and free(3).
* In the end, the pointer to the list must be NULL.
* Save the node 'next' in a 'tmp' variable, deleting actual node and moving
* the list to the 'next' node stored at 'tmp'.
*/
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *tmp;
if (!lst || !*lst || !del)
return ;
while (lst && *lst)
{
tmp = (*lst)->next;
ft_lstdelone(*lst, del);
*lst = tmp;
}
*lst = NULL;
}