-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_init.c
60 lines (55 loc) · 1.55 KB
/
ft_init.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atoof <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/11 17:32:10 by atoof #+# #+# */
/* Updated: 2023/04/11 17:32:10 by atoof ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_find_pos(char **argv, int limit, int last, t_node **stack)
{
int state;
int content;
int position;
int j;
state = last;
while (last >= limit)
{
content = ft_atoi(argv[last]);
position = 0;
j = state;
while (j >= limit)
{
if (content <= ft_atoi(argv[j]))
j--;
else
{
position++;
j--;
}
}
push(position, stack);
last--;
}
}
void ft_init(int argc, char **argv, t_node **stack)
{
int i;
if (argc > 2)
{
i = argc - 1;
ft_find_pos(argv, 1, i, stack);
}
else
{
i = 0;
while (argv[i] != NULL)
i++;
i--;
ft_find_pos(argv, 0, i, stack);
}
}