-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_list_remove.c
40 lines (37 loc) · 1.27 KB
/
ft_list_remove.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
30
31
32
33
34
35
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_list_remove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: stales <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/27 19:42:46 by stales #+# #+# */
/* Updated: 2022/03/27 21:52:05 by stales ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
void ft_list_remove(t_list **list, int index)
{
t_list *ptr;
t_list *next;
t_list *prev;
ptr = *list;
while (ptr && index--)
ptr = ptr->next;
next = ptr->next;
prev = ptr->prev;
free(ptr);
ptr = LIBFT_NULL;
if (prev == LIBFT_NULL)
{
next->prev = LIBFT_NULL;
ptr = next;
}
if (next)
{
next->prev = prev;
prev->next = next;
ptr = prev;
}
}