-
Notifications
You must be signed in to change notification settings - Fork 0
/
los_b_hermanos.c
73 lines (64 loc) · 1.75 KB
/
los_b_hermanos.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* los_b_hermanos.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 15:01:34 by zwalad #+# #+# */
/* Updated: 2022/03/23 21:40:00 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
t_swap *push_b(t_stacks *p)
{
t_swap *tmp;
t_swap *tmp2;
tmp = p->a;
tmp2 = ps_lstnew(p->a->stack);
p->b = ps_lstadd_front(p->b, tmp2);
p->a = p->a->next;
ft_printf("pb\n");
free(tmp);
return (p->b);
}
t_swap *swap_b(t_swap *b)
{
int tmp;
tmp = b->stack;
b->stack = b->next->stack;
b->next->stack = tmp;
ft_printf("sb\n");
return (b);
}
t_swap *rotate_b(t_swap *b)
{
int i;
t_swap *tmp;
t_swap *tmp2;
i = b->stack;
tmp = b;
b = b->next;
tmp2 = ps_lstnew(i);
ps_lstadd_back(b, tmp2);
ft_printf("rb\n");
tmp2 = NULL;
tmp->next = NULL;
free(tmp2);
free(tmp);
return (b);
}
t_swap *r_rotate_b(t_swap *b)
{
t_swap *tmp1;
t_swap *tmp3;
tmp1 = ps_lstlast(b);
b = ps_lstadd_front(b, ps_lstnew(tmp1->stack));
tmp3 = b;
while (tmp3->next->next != NULL)
tmp3 = tmp3->next;
tmp3->next = NULL;
free(tmp1);
ft_printf("rrb\n");
return (b);
}