-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathother_tools3.c
65 lines (60 loc) · 1.97 KB
/
other_tools3.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* other_tools3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ytaya <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/30 23:30:42 by ytaya #+# #+# */
/* Updated: 2022/01/31 12:05:27 by ytaya ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_midalgo500(t_type **stackA, t_type **stackB)
{
int *table;
int mid;
int size;
table = ft_helper(stackA);
mid = ft_midpoint500(table, ft_lstsize(*stackA));
size = ft_lstsize(*stackA) / 2;
while (ft_lstsize(*stackA) != size)
{
if (!ft_chucks_finder(*stackA, mid))
return ;
if (ft_peek(stackA) < mid)
ft_push(stackA, stackB, 'B', 1);
else if (ft_lstlast(*stackA)->num < mid)
{
ft_rrotate(stackA, 'A', 1);
ft_push(stackA, stackB, 'B', 1);
}
else
ft_rotate(stackA, 'A', 1);
}
}
void ft_rmidalgo(t_type **stackA, t_type **stackB)
{
int *table;
int mid;
int size;
table = ft_helperdes(stackB);
mid = ft_midpoint(table, ft_lstsize(*stackB));
size = ft_lstsize(*stackB) / 2;
while (ft_lstsize(*stackB) != size)
{
if (!ft_rchucks_finder(*stackB, mid))
return ;
if (ft_peek(stackB) > mid)
ft_push(stackA, stackB, 'A', 1);
else if (ft_lstlast(*stackB)->num > mid)
{
ft_rrotate(stackB, 'B', 1);
ft_push(stackA, stackB, 'A', 1);
}
else
ft_rotate(stackB, 'B', 1);
if (ft_lstsize(*stackB) == 1)
ft_push(stackA, stackB, 'A', 1);
}
}