aboutsummaryrefslogtreecommitdiff
path: root/libft/src/dlst/ft_dlstdestroy.c
blob: 6ce0d9800e5308bc3a43ccc1948c83f7ebee2e93 (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_dlstdestroy.c                                   :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: charles <charles.cabergs@gmail.com>        +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/03 15:22:51 by charles           #+#    #+#             */
/*   Updated: 2020/04/03 15:44:26 by charles          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "libft_dlst.h"

void	ft_dlstdestroy(t_ftdlst *dlst, t_ftdel_func del)
{
	if (dlst == NULL)
		return ;
	if (dlst->prev != NULL)
	{
		dlst->prev->next = NULL;
		ft_dlstdestroy(dlst->prev, del);
	}
	if (dlst->next != NULL)
	{
		dlst->next->prev = NULL;
		ft_dlstdestroy(dlst->next, del);
	}
	if (del != NULL)
		del(dlst->data);
	free(dlst);
}