-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules_rotate.c
61 lines (55 loc) · 1.74 KB
/
rules_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rules_rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amacarul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/08 15:01:54 by amacarul #+# #+# */
/* Updated: 2024/10/18 12:53:02 by amacarul ### ########.fr */
/* */
/* ************************************************************************** */
#include "libpush_swap.h"
//Rules rotate, ra, rb, rr:
//mode == 0 --> final movement, print it and do it
//mode == 1 --> calling from doble rotate (rr or rrr) or checker, not print it
//First element to last position
void ra(t_stack *a, int mode)
{
t_node *first;
t_node *last;
if (a->size < 2)
return ;
first = a->top;
last = a->top;
while ((last->next) != NULL)
last = last->next;
a->top = first->next;
last->next = first;
first->next = NULL;
if (mode == 0)
ft_printf("ra\n");
}
void rb(t_stack *b, int mode)
{
t_node *first;
t_node *last;
if (b->size < 2)
return ;
first = b->top;
last = b->top;
while ((last->next) != NULL)
last = last->next;
b->top = first->next;
last->next = first;
first->next = NULL;
if (mode == 0)
ft_printf("rb\n");
}
void rr(t_stack *a, t_stack *b, int mode)
{
ra(a, 1);
rb(b, 1);
if (mode == 0)
ft_printf("rr\n");
}