-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils2.c
101 lines (90 loc) · 2.24 KB
/
utils2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: earnaud <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/07 15:19:18 by earnaud #+# #+# */
/* Updated: 2021/07/20 16:13:15 by earnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void find_min_max(long *stack, long *min_max)
{
int i;
i = 1;
min_max[0] = stack[0];
min_max[1] = stack[0];
while (stack[i] != END_STACK)
{
if (stack[i] < min_max[0])
min_max[0] = stack[i];
if (stack[i] > min_max[1])
min_max[1] = stack[i];
i++;
}
}
long find_min(long *stack)
{
int i;
int min;
min = stack[0];
i = 1;
while (stack[i] != END_STACK)
{
if (stack[i] < min)
min = stack[i];
i++;
}
return (min);
}
// void *ft_bzero(void *str, size_t len)
// {
// size_t i;
// i = 0;
// while (i < len)
// {
// ((unsigned char *)str)[i] = 0;
// i++;
// }
// return (str);
// }
t_stacks *convert_stack(int argc, char **argv)
{
t_stacks *stack;
int i;
i = argc - 1;
stack = malloc(sizeof(t_stacks));
stack->a = malloc(sizeof(long) * (argc + 1));
stack->b = malloc(sizeof(long) * (argc + 1));
stack->size = argc - 1;
stack->a[i] = END_STACK;
stack->b[i] = END_STACK;
i--;
while (*argv)
{
stack->a[i] = ft_atoi(*argv);
stack->b[i] = END_STACK;
argv++;
i--;
}
return (stack);
}
int check_error(int argc, char **argv)
{
long temp;
if (argc <= 1)
return (1);
while (*argv)
{
if ((other_than_num(*argv) && **argv != '-') || (**argv == '-'
&& other_than_num((*argv) + 1)))
return (1);
temp = ft_atoi(*argv);
if (temp > 2147483647 || temp < -2147483648)
return (1);
argv++;
}
return (0);
}