-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_utils_2.c
60 lines (54 loc) · 1.5 KB
/
list_utils_2.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_utils_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ltombell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 11:34:17 by ltombell #+# #+# */
/* Updated: 2022/12/09 14:05:56 by ltombell ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_remove_first(t_lista **lista)
{
t_lista *tmp;
tmp = *lista;
if ((*lista)->next)
{
*lista = (*lista)->next;
(*lista)->prev = NULL;
free (tmp);
}
else
{
free(tmp);
*lista = NULL;
}
}
t_lista *ft_list_last(t_lista *lst)
{
if (!lst)
return (NULL);
while (lst->next)
lst = lst->next;
return (lst);
}
void ft_remove_last(t_lista **lista)
{
t_lista *tmp;
t_lista *tmp2;
tmp = *lista;
while ((*lista)->next)
*lista = (*lista)->next;
if ((*lista)->prev)
{
tmp2 = *lista;
*lista = (*lista)->prev;
(*lista)->next = NULL;
free (tmp2);
}
else
(*lista) = NULL;
*lista = tmp;
}