-
Notifications
You must be signed in to change notification settings - Fork 0
/
ps_lot.c
88 lines (81 loc) · 1.84 KB
/
ps_lot.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ps_lot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/11 18:48:46 by zwalad #+# #+# */
/* Updated: 2022/03/23 17:24:49 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
t_stacks *ps_indixing(t_stacks *p)
{
int i;
t_swap *tmp;
tmp = p->a;
while (tmp != NULL)
{
i = 0;
while (i < p->arg)
{
if (tmp->stack == p->tab[i])
{
tmp->stack = i;
break ;
}
i++;
}
tmp = tmp->next;
}
return (p);
}
t_stacks *ps_push_to_b(t_stacks *p)
{
int i;
int low;
i = 0;
low = 0;
while (p->a != NULL)
{
i = 0;
low = low + (p->arg / 10) + 1;
while (i < ((p->arg / 10) + 1) && p->a != NULL)
{
if (p->a->stack <= low)
{
p->b = push_b(p);
i++;
}
else if (p->a->stack > low && p->a != NULL)
p = get_lower(p, low);
}
}
return (p);
}
void ps_looot(t_stacks *p)
{
int i;
p = sort_tab(p);
p = ps_indixing(p);
p = ps_push_to_b(p);
i = p->arg - 1;
while (p->b != NULL)
{
if (p->b->stack == i)
{
p->a = push_a(p);
i--;
}
else if (p->b->stack != i)
{
p->b = get_highest(p->b, i);
if (p->b->stack == i)
{
p->a = push_a(p);
i--;
}
}
}
}