-
Notifications
You must be signed in to change notification settings - Fork 0
/
moves_ra.c
51 lines (46 loc) · 1011 Bytes
/
moves_ra.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
#include "push_swap.h"
void ra(t_two_stacks **stacks)
{
t_stack *to_free;
t_two_stacks *change;
t_stack *tmp;
t_stack *save;
change = *stacks;
save = change->a->next;
tmp = new_stack(change->a->value, stacks);
tmp->index = change->a->index;
tmp->chunk = change->a->chunk;
tmp->chunk_b = change->a->chunk_b;
to_free = change->a;
while (change->a->next)
change->a = change->a->next;
change->a->next = tmp;
change->a = save;
free(to_free);
write(1, "ra\n", 3);
}
void rb(t_two_stacks **stacks)
{
t_stack *to_free;
t_two_stacks *change;
t_stack *tmp;
t_stack *save;
change = *stacks;
save = change->b->next;
tmp = new_stack(change->b->value, stacks);
tmp->index = change->b->index;
tmp->chunk = change->b->chunk;
tmp->chunk_b = change->b->chunk_b;
to_free = change->b;
while (change->b->next)
change->b = change->b->next;
change->b->next = tmp;
change->b = save;
free(to_free);
write(1, "rb\n", 3);
}
void rr(t_two_stacks **stacks)
{
ra(stacks);
rb(stacks);
}