-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_utils.c
65 lines (57 loc) · 1.57 KB
/
list_utils.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
61
62
63
64
65
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bpochlau <poechlauerbe@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/10 09:06:16 by bpochlau #+# #+# */
/* Updated: 2023/11/18 20:02:43 by bpochlau ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
t_list *ft_lstnew(int num)
{
t_list *new;
new = malloc(sizeof(t_list));
if (!new)
return (NULL);
new->num = num;
new->i = 0;
new->next = NULL;
return (new);
}
void ft_lstadd_front(t_list **lst, t_list *new)
{
new->next = *lst;
*lst = new;
}
t_list *ft_lstlast(t_list *lst)
{
if (!lst)
return (NULL);
while (lst->next)
lst = lst->next;
return (lst);
}
t_list *ft_lstsecondlast(t_list *lst)
{
if (!lst)
return (NULL);
if (!lst->next)
return (NULL);
while (lst->next->next)
lst = lst->next;
return (lst);
}
void ft_lstadd_back(t_list **lst, t_list *new)
{
t_list *ptr;
if (lst && *lst)
{
ptr = ft_lstlast(*lst);
ptr->next = new;
}
else
*lst = new;
}