-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
85 lines (76 loc) · 1.73 KB
/
utils.c
File metadata and controls
85 lines (76 loc) · 1.73 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kikiz <kikiz@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/23 19:20:57 by kikiz #+# #+# */
/* Updated: 2025/03/26 14:58:06 by kikiz ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void free_stack(t_stack **stack)
{
t_stack *tmp;
if (!stack || !(*stack))
return ;
while (*stack)
{
tmp = (*stack)->next;
free(*stack);
*stack = tmp;
}
*stack = NULL;
}
void exit_error(char **tmp, char *str)
{
ft_freestr(tmp);
free(str);
write(2, "Error\n", 6);
exit(1);
}
long int ft_atol(const char *str)
{
long int nb;
int isneg;
int i;
nb = 0;
isneg = 1;
i = 0;
if (str[i] == '+')
i++;
else if (str[i] == '-')
{
isneg *= -1;
i++;
}
while (is_digit(str[i]))
{
nb = (nb * 10) + (str[i] - '0');
i++;
}
return (nb * isneg);
}
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i])
{
write(1, &str[i], 1);
i++;
}
}
int is_sorted(t_stack *stack)
{
if (!stack)
return (0);
while (stack->next)
{
if (stack->value > stack->next->value)
return (0);
stack = stack->next;
}
return (1);
}