-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_op_rotate.c
59 lines (51 loc) · 1.73 KB
/
ft_op_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_op_rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lhelena <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/12 18:23:23 by lhelena #+# #+# */
/* Updated: 2022/02/23 15:11:26 by lhelena ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void ft_op_rotate(t_stack **list)
{
t_stack *tmp;
t_stack *down;
tmp = *list;
*list = (*list)->next;
down = *list;
while (down->next)
down = down->next;
down->next = tmp;
down->next->next = NULL;
}
void ft_op_ra(t_stack **list_a, t_stack **list_b)
{
t_stack *tmp;
tmp = *list_b;
if (ft_elements_count(*list_a) < 2)
return ;
ft_op_rotate(list_a);
write(1, "ra\n", 3);
}
void ft_op_rb(t_stack **list_a, t_stack **list_b)
{
t_stack *tmp;
tmp = *list_a;
if (ft_elements_count(*list_b) < 2)
return ;
ft_op_rotate(list_b);
write(1, "rb\n", 3);
}
void ft_op_rr(t_stack **list_a, t_stack **list_b)
{
if (ft_elements_count(*list_a) > 1)
ft_op_rotate(list_a);
if (ft_elements_count(*list_b) > 1)
ft_op_rotate(list_b);
if ((ft_elements_count(*list_a) > 1) || (ft_elements_count(*list_b) > 1))
write(1, "rr\n", 3);
}