-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoves.c
90 lines (81 loc) · 2.06 KB
/
moves.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* moves.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ltombell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 11:34:30 by ltombell #+# #+# */
/* Updated: 2022/12/11 11:32:59 by ltombell ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ra_rb(t_lista **lista, char c)
{
t_lista *tmp;
t_lista *putback;
if ((*lista)->next != NULL)
{
putback = *lista;
tmp = *lista;
while (tmp->next)
tmp = tmp->next;
*lista = (*lista)->next;
tmp->next = putback;
putback->next = NULL;
putback->prev = tmp;
if (c == 'a')
write(1, "ra\n", 3);
else if (c == 'b')
write(1, "rb\n", 3);
}
}
void rra_rrb(t_lista **head, char c)
{
t_lista *tmp;
t_lista *prev;
if (*head == NULL || (*head)->next == NULL)
return ;
else
{
tmp = *head;
prev = *head;
while (tmp->next != NULL)
{
prev = tmp;
tmp = tmp->next;
}
prev->next = NULL;
tmp->next = *head;
tmp->prev = NULL;
tmp->next->prev = tmp;
*head = tmp;
}
if (c == 'a')
write(1, "rra\n", 4);
if (c == 'b')
write(1, "rrb\n", 4);
}
void pa_pb(t_lista **a, t_lista **b, char c)
{
int tmp;
tmp = (*a)->nb;
ft_add_element_to_start(b, tmp);
ft_remove_first(a);
if (c == 'a')
write(1, "pa\n", 3);
else if (c == 'b')
write(1, "pb\n", 3);
}
void rab(t_lista **a, t_lista **b)
{
ra_rb(a, 0);
ra_rb(b, 0);
write(1, "rr\n", 3);
}
void rrab(t_lista **a, t_lista **b)
{
rra_rrb(a, 0);
rra_rrb(b, 0);
write(1, "rrr\n", 4);
}