-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathop_rotate.c
49 lines (43 loc) · 1.44 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* op_rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sanmetol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/30 15:10:02 by sanmetol #+# #+# */
/* Updated: 2024/07/30 16:46:30 by sanmetol ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void rotate(t_node **stack)
{
t_node *last_node;
if (!*stack || !(*stack)->next)
return ;
last_node = find_last_node(*stack);
last_node->next = *stack;
(*stack)->prev = last_node;
*stack = (*stack)->next;
(*stack)->prev = NULL;
last_node->next->next = NULL;
}
void ra(t_node **a, bool print)
{
rotate(a);
if (print)
write(1, "ra\n", 3);
}
void rb(t_node **b, bool print)
{
rotate(b);
if (print)
write(1, "rb\n", 3);
}
void rr(t_node **a, t_node **b, bool print)
{
rotate(a);
rotate(b);
if (print)
write(1, "rr\n", 3);
}