-
Notifications
You must be signed in to change notification settings - Fork 1
/
rotate_opns.c
80 lines (73 loc) · 1.93 KB
/
rotate_opns.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rotate_opns.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akaraban <akaraban@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/15 00:40:08 by akaraban #+# #+# */
/* Updated: 2023/04/15 00:40:09 by akaraban ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void rotate(t_stack **stack, int reverse)
{
t_stack *last;
t_stack *trav;
t_stack *after_trav;
trav = *stack;
while (trav->next != NULL)
{
after_trav = trav;
trav = trav->next;
}
last = trav;
trav = *stack;
last->next = trav;
if (reverse == 0)
{
*stack = (*stack)->next;
trav->next = NULL;
}
else
{
*stack = last;
after_trav->next = NULL;
}
}
void ra(t_stack **stack_a, t_stack **stack_b)
{
(void)stack_b;
if (*stack_a != NULL && (*stack_a)->next != NULL)
{
rotate(stack_a, 0);
ft_putendl_fd("ra", 1);
}
}
void rb(t_stack **stack_a, t_stack **stack_b)
{
(void)stack_a;
if (*stack_b != NULL && (*stack_b)->next != NULL)
{
rotate(stack_b, 0);
ft_putendl_fd("rb", 1);
}
}
void rra(t_stack **stack_a, t_stack **stack_b)
{
(void)stack_b;
if (*stack_a != NULL && (*stack_a)->next != NULL)
{
rotate(stack_a, 1);
ft_putendl_fd("rra", 1);
}
}
void rrb(t_stack **stack_a, t_stack **stack_b)
{
(void)stack_a;
if (*stack_b != NULL && (*stack_b)->next != NULL)
{
rotate(stack_b, 1);
ft_putendl_fd("rrb", 1);
}
}