-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps_rules_more.c
95 lines (84 loc) · 2.4 KB
/
ps_rules_more.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
91
92
93
94
95
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ps_rules_more.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: agarijo- <agarijo-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/11 18:10:34 by agarijo- #+# #+# */
/* Updated: 2023/04/19 17:46:44 by agarijo- ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void reverse_rotate_a_rra(t_node **head, int a_cost)
{
t_node *old_head;
t_node *new_last;
(void)a_cost;
old_head = *head;
new_last = lst_second_to_last(*head);
*head = lst_last(*head);
new_last->next = NULL;
(*head)->next = old_head;
write(1, "rra\n", 4);
}
void reverse_rotate_b_rrb(t_node **head, int b_cost)
{
t_node *old_head;
t_node *new_last;
(void)b_cost;
old_head = *head;
new_last = lst_second_to_last(*head);
*head = lst_last(*head);
new_last->next = NULL;
(*head)->next = old_head;
write(1, "rrb\n", 4);
}
void reverse_rotate_a_b_rrr(t_node **head_a, t_node **head_b,
int a_cost, int b_cost)
{
t_node *old_head_a;
t_node *old_head_b;
t_node *new_last;
(void)a_cost;
(void)b_cost;
old_head_a = *head_a;
new_last = lst_second_to_last(*head_a);
*head_a = lst_last(*head_a);
new_last->next = NULL;
(*head_a)->next = old_head_a;
old_head_b = *head_b;
new_last = lst_second_to_last(*head_b);
*head_b = lst_last(*head_b);
new_last->next = NULL;
(*head_b)->next = old_head_b;
write(1, "rrr\n", 4);
}
void push_b_pb(t_node **head_a, t_node **head_b)
{
t_node *node_a;
t_node *node_b;
if (head_a)
{
node_a = (*head_a)->next;
node_b = *head_b;
*head_b = *head_a;
(*head_b)->next = node_b;
*head_a = node_a;
write(1, "pb\n", 3);
}
}
void push_a_pa(t_node **head_a, t_node **head_b)
{
t_node *node_a;
t_node *node_b;
if (head_a)
{
node_a = *head_a;
node_b = (*head_b)->next;
*head_a = *head_b;
(*head_a)->next = node_a;
*head_b = node_b;
write(1, "pa\n", 3);
}
}