-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotate.c
More file actions
57 lines (50 loc) · 1.68 KB
/
rotate.c
File metadata and controls
57 lines (50 loc) · 1.68 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ldiaz-ra <ldiaz-ra@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/19 13:48:53 by ldiaz-ra #+# #+# */
/* Updated: 2024/01/23 12:53:13 by ldiaz-ra ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void rotate(t_stack **stack, char *str)
{
t_stack *aux;
if (!stack || !(*stack) || !((*stack)->next))
return ;
aux = lstlast(*stack);
aux->next = (*stack);
(*stack) = (*stack)->next;
aux->next->next = NULL;
if (str)
write(1, str, 3);
}
void rotate_rr(t_stack **stack_a, t_stack **stack_b)
{
rotate(stack_a, NULL);
rotate(stack_b, NULL);
write(1, "rr\n", 3);
}
void rotate_reverse(t_stack **stack, char *str)
{
t_stack *aux;
if (!stack || !(*stack) || !((*stack)->next))
return ;
aux = *stack;
while (aux->next->next)
aux = aux->next;
aux->next->next = (*stack);
(*stack) = aux->next;
aux->next = NULL;
if (str)
write(1, str, 4);
}
void rotate_rrr(t_stack **stack_a, t_stack **stack_b)
{
rotate_reverse(stack_a, NULL);
rotate_reverse(stack_b, NULL);
write(1, "rrr\n", 4);
}