-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_free.c
51 lines (46 loc) · 1.39 KB
/
utils_free.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: denizozd <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/18 17:25:07 by denizozd #+# #+# */
/* Updated: 2024/05/27 19:57:05 by denizozd ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
/* Frees the memory allocated for the linked list. */
void free_lst(t_node *head)
{
t_node *tmp;
while (head)
{
tmp = head->next;
free(head);
head = tmp;
}
}
/* Frees all memory allocated in the main function,
including linked list and command line arguments. */
int free_all(t_node *stack_a, int ac, char **av)
{
int i;
free_lst(stack_a);
if (av == 0)
{
free(av);
return (0);
}
i = 0;
if (ac == 2)
{
while (av[i])
{
free(av[i]);
i++;
}
free(av);
}
return (0);
}