-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules_swap.c
58 lines (52 loc) · 1.68 KB
/
rules_swap.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rules_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amacarul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/08 14:05:17 by amacarul #+# #+# */
/* Updated: 2024/10/18 12:53:11 by amacarul ### ########.fr */
/* */
/* ************************************************************************** */
#include "libpush_swap.h"
//Rules swap sa, sb y ss:
//mode == 0 --> final movement, print it and do it
//mode == 1 --> calling from doble rotate (ss) or checker, not print it
//swap first two elements of a
void sa(t_stack *a, int mode)
{
t_node *first;
t_node *second;
if (a->size < 2)
return ;
first = a->top;
second = first->next;
first->next = second->next;
second->next = first;
a->top = second;
if (mode == 0)
ft_printf("sa\n");
}
//swap first two elements of b
void sb(t_stack *b, int mode)
{
t_node *first;
t_node *second;
if (b->size < 2)
return ;
first = b->top;
second = first->next;
first->next = second->next;
second->next = first;
b->top = second;
if (mode == 0)
ft_printf("sb\n");
}
void ss(t_stack *a, t_stack *b, int mode)
{
sa(a, 1);
sb(b, 1);
if (mode == 0)
ft_printf("ss\n");
}