-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_function_3.c
95 lines (84 loc) Β· 1.86 KB
/
utils_function_3.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_function_3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahajji <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/31 23:37:54 by ahajji #+# #+# */
/* Updated: 2023/02/01 23:20:25 by ahajji ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int ft_lstsize(t_list *lst)
{
t_list *tmp;
int count;
tmp = lst;
count = 0;
while (tmp)
{
tmp = tmp->next;
count++;
}
return (count);
}
t_list *ft_beforlast(t_list *lst)
{
t_list *node;
t_list *tmp;
node = ft_lstlast(lst);
while (lst)
{
if (lst->next == node)
tmp = lst;
lst = lst->next;
}
return (tmp);
}
void free_all(t_data *data, t_list **lst)
{
int i;
i = 0;
while (i < data->num_arg)
{
free(data->ret_split[i]);
i++;
}
free(data->ret_split);
while (*lst)
{
free(*lst);
*lst = (*lst)->next;
}
*lst = NULL;
free(data->integers);
exit(0);
}
void print_error_free(t_data *data)
{
int i;
i = 0;
while (i < data->num_arg)
{
free(data->ret_split[i]);
i++;
}
free(data->ret_split);
free(data->integers);
write(2, "error", 5);
exit(1);
}
void print_error_free_2(t_data *data)
{
int i;
i = 0;
while (i < data->num_arg)
{
free(data->ret_split[i]);
i++;
}
free(data->ret_split);
write(2, "error", 5);
exit(1);
}