-
Notifications
You must be signed in to change notification settings - Fork 0
/
push_swap.c
55 lines (51 loc) · 1.71 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kristori <kristori@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/17 14:37:15 by kristori #+# #+# */
/* Updated: 2023/01/12 11:35:28 by kristori ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int main(int argc, char **argv)
{
t_stack *stack_a;
t_stack *stack_b;
t_stack *sort;
int n;
if (argc <= 1)
return (1);
n = argc - 1;
stack_a = NULL;
stack_b = NULL;
sort = NULL;
if (ft_check(argv, n) == 1)
return (1);
ft_init_stack(&stack_a, argv, n);
ft_init_stack(&sort, argv, n);
ft_case(stack_a, stack_b, sort);
return (0);
}
void ft_case(t_stack *stack_a, t_stack *stack_b, t_stack *sort)
{
if (ft_is_sorted(stack_a) != 0)
{
if (ft_stack_len(stack_a) == 2)
ft_sort_2_n_stack(&stack_a);
else if (ft_stack_len(stack_a) == 3)
ft_sort_3_n_stack(&stack_a);
else if (ft_stack_len(stack_a) == 5)
ft_sort_5_n(&stack_a, &stack_b);
else
{
ft_sort_stack(sort);
ft_order_stack(stack_a, sort);
ft_sort_big_stack(&stack_a, &stack_b);
}
}
ft_free_stack(stack_a);
ft_free_stack(sort);
}