-
Notifications
You must be signed in to change notification settings - Fork 0
/
effective_operations.c
65 lines (60 loc) · 1.83 KB
/
effective_operations.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* effective_operations.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pgober <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 10:23:42 by pgober #+# #+# */
/* Updated: 2023/11/05 10:28:15 by pgober ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int rotation_decision1(t_stack **head, t_stack **head2, char ab, bool print)
{
int i;
i = 0;
while (*head && ascndng(last_node(*head), *head))
{
if (*head2 && ascndng(*head2, last_node(*head2)))
{
rr(head, head2, print);
i++;
}
else if (list_len(*head) - smallest_pos12(*head) \
<= smallest_pos12(*head))
{
rrab(head, ab, print);
i++;
}
else
{
rab(head, ab, print);
i++;
}
}
return (i);
}
int swap_decision1(t_stack **head, t_stack **head2, char ab, bool print)
{
int i;
i = 0;
if ((*head)->next && ascndng((*head)->next, *head) && ab == 'a')
{
if (*head2 && (*head2)->next && ascndng(*head2, (*head2)->next))
ss(head, head2, print);
else
sab(head, ab, print);
i++;
}
if (*head2 && (*head2)->next && ascndng(*head2, (*head2)->next) \
&& ab == 'b')
{
if ((*head)->next && ascndng((*head)->next, *head))
ss(head, head2, print);
else
sab(head, ab, print);
i++;
}
return (i);
}