-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
105 lines (95 loc) · 2.41 KB
/
main.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
96
97
98
99
100
101
102
103
104
105
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: earnaud <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/31 02:17:21 by earnaud #+# #+# */
/* Updated: 2021/08/04 14:49:09 by earnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
// void print_list(long *stack)
// {
// int i;
// i = stack_nb(stack);
// while (i >= 0)
// {
// printf("|%3ld|\n", stack[i]);
// i--;
// }
// printf("\n--------------\n----------------\n");
// }
// void print_stacks(t_stacks *stacks)
// {
// int i;
// int j;
// i = stack_nb(stacks->a);
// j = stack_nb(stacks->b);
// if (j > i)
// i = j;
// while (i >= 0)
// {
// if (j == -1)
// printf(" |%3ld| |not|\n", stacks->a[i]);
// else
// printf(" |%3ld| |%3ld|\n", stacks->a[i], stacks->b[i]);
// i--;
// }
// printf("\n----------------------\n----------------------\n");
// }
void ft_magic(t_stacks *stacks, int nbr)
{
if (nbr == 1 || check_sorted(stacks))
return ;
else if (nbr == 2)
algo_for_2(stacks);
else if (nbr == 3)
algo_for_3(stacks);
else if (nbr == 5)
algo_for_5(stacks);
else
insertionv2(stacks, stacks->size);
}
int check_double_in_a(t_stacks *stacks)
{
long temp;
int i;
int j;
j = stack_nb(stacks->a);
while (j >= 0)
{
i = stack_nb(stacks->a);
temp = stacks->a[j];
while (i >= 0)
{
if (temp == stacks->a[i] && i != j)
return (1);
i--;
}
j--;
}
return (0);
}
int main(int argc, char **argv)
{
t_stacks *stacks;
if (argc == 1)
return (0);
if (check_error(argc, argv + 1))
return (error(-1));
stacks = convert_stack(argc, argv + 1);
if (check_double_in_a(stacks))
{
free(stacks->a);
free(stacks->b);
free(stacks);
return (error(-1));
}
ft_magic(stacks, argc - 1);
free(stacks->a);
free(stacks->b);
free(stacks);
return (0);
}