-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_swap.c
92 lines (83 loc) · 1.92 KB
/
push_swap.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amtadevo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/22 16:55:48 by amtadevo #+# #+# */
/* Updated: 2022/11/24 19:54:14 by amtadevo ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void error_check(char **str)
{
int j;
j = 0;
while (str[j])
{
fake_atoi(str[j]);
j++;
}
check_duplicates(str, j);
zeros_validation(str, j);
}
void small_sort(int size, t_stack **a, t_stack **b)
{
if (size == 2)
sort2(a);
else if (size == 3)
sort3(a);
else if (size == 4)
sort4(a, b);
else if (size == 5)
sort5(a, b);
}
void sort(t_stack **a, t_stack **b)
{
int size;
size = ft_lstsize(*a);
if (size <= 5)
{
small_sort(size, a, b);
ft_lstclear(a, del);
ft_lstclear(b, del);
}
else
{
indexing(*a);
butterfly(a, b);
ft_lstclear(a, del);
ft_lstclear(b, del);
}
}
// ./push_swap 8 9 4 5 6 1 2 3 7
int main(int argc, char **argv)
{
char **str;
t_stack *a;
t_stack *b;
if (argc > 1)
{
a = NULL;
b = NULL;
str = argv_parsing(argc, argv);
if (!str || !str[0])
return (0);
error_check(str);
a = fill_stack(str);
free_str(str);
if (is_sorted(a))
{
ft_lstclear(&a, del);
ft_lstclear(&b, del);
return (0);
}
sort(&a, &b);
}
while (1)
{
/* code */
}
return (0);
}