-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations.c
78 lines (69 loc) · 1.88 KB
/
operations.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* operations.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: earnaud <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/31 02:56:25 by earnaud #+# #+# */
/* Updated: 2021/07/16 16:47:51 by earnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void switch_rr(t_stacks *stack)
{
write(STDOUT_FILENO, "rr\n", 3);
switch_ra(stack, 0);
switch_rb(stack, 0);
}
void switch_rb(t_stacks *stack, int write_it)
{
int i;
int temp;
if (write_it)
write(STDOUT_FILENO, "rb\n", 3);
i = stack_nb(stack->b);
temp = stack->b[stack_nb(stack->b)];
while (i)
{
stack->b[i] = stack->b[i - 1];
i--;
}
stack->b[i] = temp;
}
void switch_ra(t_stacks *stack, int write_it)
{
int i;
int temp;
if (write_it)
write(STDOUT_FILENO, "ra\n", 3);
i = stack_nb(stack->a);
temp = stack->a[stack_nb(stack->a)];
while (i)
{
stack->a[i] = stack->a[i - 1];
i--;
}
stack->a[i] = temp;
}
void switch_rrr(t_stacks *stack)
{
write(STDOUT_FILENO, "rrr\n", 4);
switch_rra(stack, 0);
switch_rrb(stack, 0);
}
void switch_rrb(t_stacks *stack, int write_it)
{
int i;
int temp;
if (write_it)
write(STDOUT_FILENO, "rrb\n", 4);
i = 0;
temp = stack->b[0];
while (i < stack_nb(stack->b))
{
stack->b[i] = stack->b[i + 1];
i++;
}
stack->b[i] = temp;
}