-
Notifications
You must be signed in to change notification settings - Fork 0
/
various_utils.c
80 lines (71 loc) · 1.76 KB
/
various_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* various_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ltombell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 11:33:59 by ltombell #+# #+# */
/* Updated: 2022/12/10 10:37:24 by ltombell ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
long ft_atoi(const char *nptr)
{
int i;
long result;
int sign;
i = 0;
result = 0;
sign = 1;
while (nptr[i] == 32 || (nptr[i] >= 9 && nptr[i] <= 13))
i++;
if (nptr[i] == '+' || nptr[i] == '-')
{
if (nptr[i] == '-')
sign *= -1;
i++;
}
while (nptr[i] >= '0' && nptr[i] <= '9')
{
result = result * 10 + nptr[i] - '0';
i++;
}
return (result * sign);
}
int ft_find_min(t_lista *lista)
{
int tmpmin;
tmpmin = lista->nb;
while (lista)
{
if (lista->nb < tmpmin)
tmpmin = lista->nb;
lista = lista->next;
}
return (tmpmin);
}
int ft_absolute(int nb)
{
if (nb < 0)
nb *= -1;
return (nb);
}
int ft_is_number(char c)
{
if (c < '0' || c > '9')
return (0);
return (1);
}
int ft_is_list_ordered(t_lista *lst)
{
t_lista *tmp;
tmp = lst;
while (tmp->next)
{
if (tmp->nb > tmp->next->nb)
return (0);
tmp = tmp->next;
}
return (1);
}