-
Notifications
You must be signed in to change notification settings - Fork 0
/
reverse_rotate.c
65 lines (59 loc) · 1.63 KB
/
reverse_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* reverse_rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rlechapt <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/01/24 05:20:37 by rlechapt #+# #+# */
/* Updated: 2015/02/24 17:00:18 by rlechapt ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void reverse_rotate_a(t_env *e, t_flags *f)
{
int tmp;
int i;
if (e->len_a < 2)
return ;
i = e->len_a - 1;
tmp = e->pile_a[i];
while (i >= 0)
{
e->pile_a[i] = e->pile_a[i - 1];
i--;
}
e->pile_a[0] = tmp;
e->count += 1;
ft_putstr("rra ");
if (f->v == 1)
stack_status(e);
}
void reverse_rotate_b(t_env *e, t_flags *f)
{
int tmp;
int i;
if (e->len_b < 2)
return ;
i = e->len_b - 1;
tmp = e->pile_b[i];
while (i >= 0)
{
e->pile_b[i] = e->pile_b[i - 1];
i--;
}
e->pile_b[0] = tmp;
e->count += 1;
ft_putstr("rrb ");
if (f->v == 1)
stack_status(e);
}
void reverse_rotate_r(t_env *e, t_flags *f)
{
reverse_rotate_a(e, f);
reverse_rotate_b(e, f);
e->count -= 1;
ft_putstr("rrr ");
if (f->v == 1)
stack_status(e);
}