-
Notifications
You must be signed in to change notification settings - Fork 0
/
stackfunctions2.c
63 lines (57 loc) · 1.71 KB
/
stackfunctions2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stackfunctions2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hde-vos <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/08/01 17:28:54 by hde-vos #+# #+# */
/* Updated: 2019/09/09 12:51:40 by hde-vos ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_ra(t_stack **stack_a, int i)
{
t_stack *first;
t_stack *last;
if ((!*stack_a) || (stacksize(*stack_a) < 2))
return ;
first = *stack_a;
last = *stack_a;
while (last->next != NULL)
last = last->next;
*stack_a = first->next;
first->next = NULL;
last->next = first;
first->prev = last;
if (i == 1)
write(1, "ra\n", 3);
}
void ft_rb(t_stack **stackb, int n)
{
t_stack *first;
t_stack *last;
t_stack *temp;
first = *stackb;
last = *stackb;
temp = first->next;
if (first && last)
{
while (last->next)
last = last->next;
last->next = first;
first->prev = last;
first->next = NULL;
temp->prev = NULL;
*stackb = temp;
if (n == 1)
write(1, "rb\n", 3);
}
}
void ft_rr(t_stack **stacka, t_stack **stackb, int i)
{
ft_ra(stacka, 0);
ft_ra(stackb, 0);
if (i == 1)
write(1, "rr\n", 3);
}