-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovements.c
76 lines (67 loc) · 2.04 KB
/
movements.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
70
71
72
73
74
75
76
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* movements.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atoof <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/11 17:31:44 by atoof #+# #+# */
/* Updated: 2023/04/11 17:31:44 by atoof ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void pa(t_node **stack_a, t_node **stack_b)
{
if (!*stack_b)
return ;
push(pop(stack_b), stack_a);
ft_printf("pa\n");
}
void sa(t_node **stack_a)
{
int top_data;
int next_data;
if (*stack_a == NULL || (*stack_a)->next == NULL)
return ;
top_data = (*stack_a)->data;
next_data = (*stack_a)->next->data;
(*stack_a)->data = next_data;
(*stack_a)->next->data = top_data;
ft_printf("sa\n");
}
void ra(t_node **stack_a)
{
t_node *tail;
if (*stack_a == NULL || (*stack_a)->next == NULL)
return ;
tail = *stack_a;
while (tail->next != NULL)
tail = tail->next;
tail->next = *stack_a;
*stack_a = (*stack_a)->next;
tail->next->next = NULL;
ft_printf("ra\n");
}
void rra(t_node **stack_a)
{
t_node *bottom;
t_node *tmp;
if (!*stack_a)
return ;
bottom = *stack_a;
tmp = *stack_a;
while (tmp->next->next != NULL)
tmp = tmp->next;
bottom = tmp->next;
tmp->next = NULL;
bottom->next = *stack_a;
*stack_a = bottom;
ft_printf("rra\n");
}
void pb(t_node **stack_a, t_node **stack_b)
{
if (!*stack_a)
return ;
push(pop(stack_a), stack_b);
ft_printf("pb\n");
}