-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate_stack.c
More file actions
59 lines (52 loc) · 1.73 KB
/
populate_stack.c
File metadata and controls
59 lines (52 loc) · 1.73 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* populate_stack.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cborrome <cborrome@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 11:36:16 by cborrome #+# #+# */
/* Updated: 2025/02/17 13:19:40 by cborrome ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int num_arguments(t_data *data)
{
int i;
i = 0;
while (data->arguments[i])
i++;
return (i);
}
void populate_stack_a(t_data *data)
{
int i;
long number;
i = 0;
data->stack_a = (int *)malloc(num_arguments(data) * sizeof(int));
if (!data->stack_a)
error_free_exit(data);
data->size_a = 0;
while (data->arguments[i])
{
number = ft_atoi(data->arguments[i], data);
if (number > INT_MAX || number < INT_MIN)
error_free_exit(data);
data->stack_a[i] = (int)number;
data->size_a++;
i++;
}
}
void allocate_stack_b(t_data *data)
{
data->stack_b = (int *)malloc(num_arguments(data) * sizeof(int));
if (!data->stack_b)
error_free_exit(data);
data->size_b = 0;
}
void allocate_move(t_data *data, t_move *move)
{
move = (t_move *)malloc((data->size_a + data->size_b) * sizeof(t_move));
if (!move)
error_free_exit(data);
}