Repository navigation
Expand file tree
/
Copy pathstack_helper.c
More file actions
73 lines (64 loc) · 1.63 KB
/
Copy pathstack_helper.c
File metadata and controls
73 lines (64 loc) · 1.63 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stack_helper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aait-idi <aait-idi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/20 23:35:20 by aait-idi #+# #+# */
/* Updated: 2026/02/08 22:21:26 by aait-idi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int stack_size(t_stack *stack)
{
int i;
if (!stack)
return (0);
i = 1;
while (stack->next)
{
i++;
stack = stack->next;
}
return (i);
}
t_stack *stack_new(void)
{
t_stack *new;
new = malloc(sizeof(t_stack));
if (!new)
return (NULL);
new->next = NULL;
return (new);
}
t_stack *stack_last(t_stack *stack)
{
if (!stack)
return (NULL);
while (stack->next)
stack = stack->next;
return (stack);
}
void stack_add_front(t_stack **stack, t_stack *new)
{
if (!stack || !new)
return ;
new->next = *stack;
*stack = new;
}
void stack_clear(t_stack **stack)
{
t_stack *iter;
t_stack *next;
if (!stack || !*stack)
return ;
iter = *stack;
while (iter)
{
next = iter->next;
free(iter);
iter = next;
}
*stack = NULL;
}