-
Notifications
You must be signed in to change notification settings - Fork 0
/
move_r.c
64 lines (58 loc) · 1.81 KB
/
move_r.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move_r.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eelasam <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/11 14:48:46 by eelasam #+# #+# */
/* Updated: 2023/04/14 14:32:30 by eelasam ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
/* ra (rotate a): Shift up all elements of stack a by 1.
The first element becomes the last one. */
void ra(t_stack *stack, int flag)
{
int tmp;
int i;
i = 0;
if (stack->a_size < 2)
return ;
tmp = stack->a_stack[0];
while (i < stack->a_size - 1)
{
stack->a_stack[i] = stack->a_stack[i + 1];
i++;
}
stack->a_stack[stack->a_size - 1] = tmp;
if (flag == 1)
write(1, "ra\n", 3);
}
/* rb (rotate b): Shift up all elements of stack b by 1.
The first element becomes the last one. */
void rb(t_stack *stack, int flag)
{
int tmp;
int i;
i = 0;
if (stack->b_size < 2)
return ;
tmp = stack->b_stack[0];
while (i < stack->b_size - 1)
{
stack->b_stack[i] = stack->b_stack[i + 1];
i++;
}
stack->b_stack[stack->b_size - 1] = tmp;
if (flag == 1)
write(1, "rb\n", 3);
}
//rr : ra and rb at the same time.
void rr(t_stack *stack, int flag)
{
ra(stack, 0);
rb(stack, 0);
if (flag == 1)
write(1, "rr\n", 3);
}