-
Notifications
You must be signed in to change notification settings - Fork 0
/
instructions_3.c
51 lines (45 loc) · 1.75 KB
/
instructions_3.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* instructions_3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akaratas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/20 15:44:20 by akaratas #+# #+# */
/* Updated: 2024/03/20 15:45:02 by akaratas ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void reverse_rotate_a(t_list **stack_ap)
{
t_list *last;
t_list *node_iterator;
if (stack_ap == NULL || ft_lstsize(*stack_ap) <= 1)
return ;
last = ft_lstlast(*stack_ap);
node_iterator = *stack_ap;
while ((node_iterator->next)->next != NULL)
node_iterator = node_iterator->next;
node_iterator->next = NULL;
ft_lstadd_front(stack_ap, last);
write(1, "rra\n", 4);
}
void reverse_rotate_b(t_list **stack_bp)
{
t_list *last;
t_list *node_iterator;
if (stack_bp == NULL || ft_lstsize(*stack_bp) <= 1)
return ;
last = ft_lstlast(*stack_bp);
node_iterator = *stack_bp;
while ((node_iterator->next)->next != NULL)
node_iterator = node_iterator->next;
node_iterator->next = NULL;
ft_lstadd_front(stack_bp, last);
write(1, "rrb\n", 4);
}
void reverse_rotate_ab(t_list **stack_ap, t_list **stack_bp)
{
reverse_rotate_a(stack_ap);
reverse_rotate_b(stack_bp);
}