-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_big.c
92 lines (83 loc) · 2.06 KB
/
sort_big.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
89
90
91
92
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sort_big.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nenvoy <nenvoy@student.21-school.ru> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/15 16:52:22 by nenvoy #+# #+# */
/* Updated: 2021/12/15 16:52:57 by nenvoy ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static int position(t_list **stack_b, int len)
{
t_list *tmp;
int i;
i = 0;
tmp = *stack_b;
while (tmp->id != len)
{
tmp = tmp->next;
i++;
}
return (i);
}
static void sort_pa(t_list **stack_a, t_list **stack_b)
{
int len;
while ((*stack_b) != NULL)
{
len = len_node(*stack_b) - 1;
if ((*stack_b)->id != len && (len / 2) > position(stack_b, len))
rb(stack_b);
else if ((*stack_b)->id != len && (len / 2) <= position(stack_b, len))
rrb(stack_b);
else if ((*stack_b)->id == len)
pa(stack_a, stack_b);
}
}
void sort_100(t_list **stack_a, t_list **stack_b)
{
int i;
i = 0;
while ((*stack_a) != NULL)
{
if (i > 1 && (*stack_a)->id <= i)
{
pb(stack_a, stack_b);
i++;
rb(stack_b);
}
else if ((*stack_a)->id <= i + 15)
{
pb(stack_a, stack_b);
i++;
}
else
ra(stack_a);
}
sort_pa(stack_a, stack_b);
}
void sort_500(t_list **stack_a, t_list **stack_b)
{
int i;
i = 0;
while ((*stack_a) != NULL)
{
if (i > 1 && (*stack_a)->id <= i)
{
pb(stack_a, stack_b);
i++;
rb(stack_b);
}
else if ((*stack_a)->id <= i + 30)
{
pb(stack_a, stack_b),
i++;
}
else
ra(stack_a);
}
sort_pa(stack_a, stack_b);
}