-
Notifications
You must be signed in to change notification settings - Fork 0
/
reverse.c
69 lines (63 loc) · 1.69 KB
/
reverse.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* reverse.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nenvoy <nenvoy@student.21-school.ru> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/15 16:50:45 by nenvoy #+# #+# */
/* Updated: 2021/12/15 16:51:09 by nenvoy ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void rra(t_list **stack_a)
{
t_list *tmp;
t_list *first;
t_list *last;
if ((*stack_a)->next)
{
tmp = *stack_a;
while (tmp->next->next != NULL)
tmp = tmp->next;
last = tmp;
first = tmp->next;
last->next = NULL;
first->next = *stack_a;
*stack_a = first;
write(1, "rra\n", 4);
}
else
return ;
}
void rrb(t_list **stack_b)
{
t_list *tmp;
t_list *first;
t_list *last;
if ((*stack_b)->next)
{
tmp = *stack_b;
while (tmp->next->next != NULL)
tmp = tmp->next;
last = tmp;
first = tmp->next;
last->next = NULL;
first->next = *stack_b;
*stack_b = first;
write(1, "rrb\n", 4);
}
else
return ;
}
void rrr(t_list *stack_a, t_list *stack_b)
{
if ((stack_a->next) && (stack_b->next))
{
rra(&stack_a);
rrb(&stack_b);
write(1, "rrr\n", 4);
}
else
return ;
}