-
Notifications
You must be signed in to change notification settings - Fork 1
/
push_swap.c
51 lines (47 loc) · 1.65 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: agaliste <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/06 15:14:57 by agaliste #+# #+# */
/* Updated: 2022/02/21 10:06:28 by agaliste ### ########.fr */
/* */
/* ************************************************************************** */
#include "headers/pushswp.h"
static inline void
clearall(t_list **stackA, t_list **stackB, t_list **copy)
{
ft_lstclear(stackA, free);
ft_lstclear(stackB, free);
ft_lstclear(copy, free);
}
int
main(int argc, char **argv)
{
t_list *stack_a;
t_list *stack_b;
t_list *copy;
stack_a = NULL;
stack_b = NULL;
copy = NULL;
init(argv, argc, &stack_a, ©);
if (!issorted(stack_a))
{
if (ft_lstsize(stack_a) < 3)
rotate(&stack_a, ft_lstsize(stack_a), "ra\n");
else if (ft_lstsize(stack_a) <= 3)
three_sort(&stack_a);
else if (ft_lstsize(stack_a) <= 5)
five_sort(&stack_a, &stack_b);
else
{
selection_sort(©);
replacebyorder(&stack_a, copy);
big_sort(&stack_a, &stack_b, ft_lstsize(stack_a));
}
}
clearall(&stack_a, &stack_b, ©);
return (0);
}