-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_sort_tiers.c
executable file
·60 lines (55 loc) · 1.66 KB
/
ft_sort_tiers.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sort_tiers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abadidi < [email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/11 20:47:30 by abadidi #+# #+# */
/* Updated: 2021/12/12 01:17:53 by abadidi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void sort_three_help(t_sort_three_vars v, t_stack **a)
{
if (v.val0 > v.val1 && v.val1 < v.val2 && v.val0 > v.val2)
{
rotate_stack(a);
print("ra\n");
}
else if (v.val0 < v.val1 && v.val0 < v.val2 && v.val1 > v.val2)
{
swap(*a);
rotate_stack(a);
print("sa\nra\n");
}
else if (v.val2 < v.val1 && v.val1 > v.val0)
{
revers_rotate(a);
print("rra\n");
}
}
void sort_three(t_stack **a)
{
t_sort_three_vars v;
v.val0 = (*a)->val;
v.val1 = (*a)->next->val;
v.val2 = (*a)->next->next->val;
if (v.val0 > v.val1 && v.val1 < v.val2 && v.val0 < v.val2)
{
swap(*a);
print("sa\n");
}
else if (v.val0 > v.val1 && v.val1 > v.val2)
{
swap(*a);
revers_rotate(a);
print("sa\nrra\n");
}
else
sort_three_help(v, a);
}
void sort_tow(void)
{
print("sa\n");
}