-
Notifications
You must be signed in to change notification settings - Fork 0
/
optimize.c
69 lines (63 loc) · 1.68 KB
/
optimize.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* optimize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yenoh <yenoh@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/13 12:37:19 by yenoh #+# #+# */
/* Updated: 2023/11/13 22:33:25 by yenoh ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int check_ra_rb(t_ps *ps)
{
int check;
t_node *tmp;
t_node *node;
check = 0;
tmp = ps->cmd_stack->head;
while (tmp)
{
if (tmp->next && tmp->num == 5 && tmp->next->num == 6)
{
node = tmp;
tmp = tmp->next;
node->prev->next = tmp;
tmp->prev = node;
free(node);
tmp->num = 7;
check = 1;
}
tmp = tmp->next;
}
return (check);
}
int check_rb_ra(t_ps *ps)
{
int check;
t_node *tmp;
t_node *node;
check = 0;
tmp = ps->cmd_stack->head;
while (tmp)
{
if (tmp->next && tmp->num == 6 && tmp->next->num == 5)
{
node = tmp;
tmp = tmp->next;
node->prev->next = tmp;
tmp->prev = node;
free(node);
tmp->num = 7;
check = 1;
}
tmp = tmp->next;
}
return (check);
}
void optimize(t_ps *ps)
{
while (check_ra_rb(ps) || check_rb_ra(ps))
;
}