-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.c
95 lines (85 loc) · 2.15 KB
/
sort.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
93
94
95
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: igenial <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/14 23:22:53 by igenial #+# #+# */
/* Updated: 2023/11/14 23:22:54 by igenial ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void aux_five(t_main *stack, int pos)
{
if (pos == 5)
rra_dcll_list(stack);
else if (pos == 4)
{
rra_dcll_list(stack);
rra_dcll_list(stack);
}
else if (pos == 3)
{
rra_dcll_list(stack);
rra_dcll_list(stack);
rra_dcll_list(stack);
}
else if (pos == 2)
sa_dcll_list(stack);
}
void sorted_two(t_main *stack)
{
t_node *temp;
temp = stack->a->head->next;
if (stack->a->head->content > temp->content)
sa_dcll_list(stack);
}
void sorted_three(t_main *stack)
{
int pos;
pos = find_position_max(stack);
if (pos == 1)
ra_dcll_list(stack);
if (pos == 2)
rra_dcll_list(stack);
sorted_two(stack);
}
void sorted_four(t_main *stack)
{
int pos;
pos = find_position_min(stack);
if (stack->len == 4)
{
if (pos == 4)
rra_dcll_list(stack);
else if (pos == 3)
{
rra_dcll_list(stack);
rra_dcll_list(stack);
}
else if (pos == 2)
sa_dcll_list(stack);
pb_dcll_list(stack);
stack->len -= 1;
sorted_three(stack);
pa_dcll_list(stack);
stack->len += 1;
}
sorted_three(stack);
}
void sorted_five(t_main *stack)
{
int pos;
if (stack->len == 5)
{
pos = find_position_min(stack);
aux_five(stack, pos);
pb_dcll_list(stack);
stack->len -= 1;
sorted_four(stack);
pa_dcll_list(stack);
stack->len += 1;
}
sorted_four(stack);
}