-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_utils.c
More file actions
65 lines (58 loc) · 1.65 KB
/
list_utils.c
File metadata and controls
65 lines (58 loc) · 1.65 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yaqliu <yaqliu@student.42barcelona.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/02 12:07:13 by yaqliu #+# #+# */
/* Updated: 2026/02/11 22:12:42 by yaqliu ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
void ft_create_stack(char **content, int size, t_stack **stack, int *index)
{
t_stack *elem;
int i;
int pos;
long val;
*stack = NULL;
i = 0;
while (i < size)
{
val = ft_atol(content[i]);
pos = get_index(index, val, size);
elem = lstnew((int)val, pos);
lstadd_back(stack, elem);
i++;
}
}
t_stack *lstnew(int content, int pos)
{
t_stack *new;
new = (t_stack *)malloc(sizeof(t_stack));
if (!new)
return (NULL);
new -> value = content;
new -> r_pos = pos;
new -> next = NULL;
return (new);
}
void lstadd_back(t_stack **stack, t_stack *new)
{
t_stack *last;
if (!stack || !new)
{
*stack = new;
return ;
}
if (*stack == NULL)
{
*stack = new;
return ;
}
last = *stack;
while (last -> next)
last = last -> next;
last -> next = new;
}