-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathop_push.c
More file actions
57 lines (52 loc) · 1.53 KB
/
op_push.c
File metadata and controls
57 lines (52 loc) · 1.53 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* op_push.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cborrome <cborrome@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 17:30:24 by cborrome #+# #+# */
/* Updated: 2025/02/17 10:57:08 by cborrome ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void push_to_b(t_data *data)
{
int i;
data->size_b++;
i = data->size_b -1;
while (i > 0)
{
data->stack_b[i] = data->stack_b[i - 1];
i--;
}
data->stack_b[0] = data->stack_a[0];
i = 0;
while (i < data->size_a - 1)
{
data->stack_a[i] = data->stack_a[i + 1];
i++;
}
data->size_a--;
write(1, "pb\n", 3);
}
void push_to_a(t_data *data)
{
int i;
data->size_a++;
i = data->size_a -1;
while (i > 0)
{
data->stack_a[i] = data->stack_a[i - 1];
i--;
}
data->stack_a[0] = data->stack_b[0];
i = 0;
while (i < data->size_b - 1)
{
data->stack_b[i] = data->stack_b[i + 1];
i++;
}
data->size_b--;
write(1, "pa\n", 3);
}