-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_small.c
61 lines (57 loc) · 1.79 KB
/
sort_small.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sort_small.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ebeiline <ebeiline@42wolfsburg.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/16 14:01:46 by ebeiline #+# #+# */
/* Updated: 2021/11/19 15:28:38 by ebeiline ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
void sort_3(t_list **a, t_list **commands)
{
while (!is_sorted(*a))
{
if (ft_atoi((*a)->content) > ft_atoi((*a)->next->content))
ft_sa(a, commands);
else
ft_rra(a, commands);
}
}
void sort_4(t_list **a, t_list **b, t_list **commands)
{
while (ft_atoi((*a)->content) != 0)
{
if (ft_atoi((*a)->next->content) == 0)
ft_ra(a, commands);
else
ft_rra(a, commands);
}
ft_pb(a, b, commands);
sort_3(a, commands);
ft_pa(b, a, commands);
}
void sort_5(t_list **a, t_list **b, t_list **commands)
{
while (ft_atoi((*a)->content) != 0)
{
if (ft_atoi((*a)->next->content) == 0)
ft_ra(a, commands);
else
ft_rra(a, commands);
}
ft_pb(a, b, commands);
while (ft_atoi((*a)->content) != 1)
{
if (ft_atoi((*a)->next->content) == 1)
ft_ra(a, commands);
else
ft_rra(a, commands);
}
ft_pb(a, b, commands);
sort_3(a, commands);
ft_pa(b, a, commands);
ft_pa(b, a, commands);
}