-
Notifications
You must be signed in to change notification settings - Fork 0
/
3ft_stack_2.c
executable file
·85 lines (74 loc) · 1.77 KB
/
3ft_stack_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 3ft_stack_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: skarunat <skarunat@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/30 11:27:46 by skarunat #+# #+# */
/* Updated: 2023/08/05 18:22:28 by skarunat ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
t_stack *ft_new_node(int value)
{
t_stack *new;
new = (t_stack *)malloc(sizeof(*new));
if (!new)
return (NULL);
new->value = value;
new->index = -1;
new->next = NULL;
return (new);
}
t_stack *ft_last_node(t_stack *head)
{
t_stack *tmp;
tmp = head;
while (tmp->next != NULL)
{
tmp = tmp->next;
if (tmp->next == NULL)
return (tmp);
}
return (tmp);
}
void ft_node_add_back(t_stack **stack, t_stack *new)
{
t_stack *i;
if (*stack)
{
i = ft_last_node(*stack);
i->next = new;
new->next = NULL;
}
else
{
*stack = new;
(*stack)->next = NULL;
}
}
int ft_get_size(t_stack *head)
{
size_t i;
t_stack *tmp;
tmp = head;
i = 0;
while (tmp)
{
tmp = tmp->next;
i++;
}
return (i);
}
void ft_print_list(t_stack *head)
{
t_stack *tmp;
tmp = head;
while (tmp != NULL)
{
ft_putnbr_fd(tmp->value, 1);
ft_putendl_fd("", 1);
tmp = tmp->next;
}
}