-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp_r_rotate.c
76 lines (70 loc) · 2.01 KB
/
p_r_rotate.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* p_r_rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dfurneau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/17 19:54:38 by dfurneau #+# #+# */
/* Updated: 2021/12/10 03:33:03 by dfurneau ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/push_swap.h"
/**
* Common Reverse Rotate A or B
* Reverse Rotate A or B (rra)(rrb)
* Shift down all elements of stack A or B by 1
* The last element becomes the first one
**/
static void r_rotate_ab(t_stack *ab)
{
int tmp;
int i;
if (ab->len == 1)
return ;
i = 0;
tmp = ab->stack[0];
while (i < ab->len - 1)
{
ab->stack[i] = ab->stack[i + 1];
i++;
}
ab->stack[i] = tmp;
}
/**
* Reverse Rotate A
* Reverse Rotate A (rra)
* Shift down all elements of stack A by 1
* The last element becomes the first one
**/
void rra(t_stack *a)
{
r_rotate_ab(a);
if (!CHECKER)
ft_printf("rr%c\n", a->name);
}
/**
* Reverse Rotate B
* Reverse Rotate B (rrb)
* Shift down all elements of stack A by 1
* The last element becomes the first one
**/
void rrb(t_stack *b)
{
r_rotate_ab(b);
if (!CHECKER)
ft_printf("rr%c\n", b->name);
}
/**
* Reverse Rotate A and B
* Reverse Rotate A and B (rrr) Equal to (rra)(rrb)
* Shift down all elements of stack A and B by 1
* The last element becomes the first one
**/
void rrr(t_stack *a, t_stack *b)
{
r_rotate_ab(a);
r_rotate_ab(b);
if (!CHECKER)
ft_printf("rrr\n");
}