-
Notifications
You must be signed in to change notification settings - Fork 0
/
los_a_hermanos.c
78 lines (69 loc) · 1.82 KB
/
los_a_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
74
75
76
77
78
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* los_a_hermanos.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/05 18:56:43 by zwalad #+# #+# */
/* Updated: 2022/03/23 21:39:42 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
t_swap *push_a(t_stacks *p)
{
t_swap *tmp;
t_swap *tmp2;
tmp = p->b;
tmp2 = ps_lstnew(p->b->stack);
p->a = ps_lstadd_front(p->a, tmp2);
p->b = p->b->next;
ft_printf("pa\n");
free(tmp);
return (p->a);
}
t_swap *swap_a(t_swap *a)
{
int tmp;
tmp = a->stack;
a->stack = a->next->stack;
a->next->stack = tmp;
ft_printf("sa\n");
return (a);
}
t_swap *rotate_a(t_swap *a)
{
int i;
t_swap *tmp;
t_swap *tmp2;
i = a->stack;
tmp = a;
a = a->next;
tmp2 = ps_lstnew(i);
ps_lstadd_back(a, tmp2);
ft_printf("ra\n");
tmp->next = NULL;
free(tmp);
return (a);
}
t_swap *r_rotate_a(t_swap *a)
{
t_swap *tmp1;
t_swap *tmp2;
t_swap *tmp3;
if ((a == NULL) || (a->next == NULL))
return (a);
tmp1 = a;
tmp2 = a;
tmp3 = ps_lstlast(a);
a = ps_lstadd_front(a, ps_lstnew(tmp3->stack));
while (tmp1->next != NULL)
{
tmp2 = tmp1;
tmp1 = tmp1->next;
}
tmp2->next = NULL;
free(tmp1);
ft_printf("rra\n");
return (a);
}