-
Notifications
You must be signed in to change notification settings - Fork 0
/
free_stack.c
51 lines (46 loc) · 1.31 KB
/
free_stack.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free_stack.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aheinane <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/11 11:54:34 by aheinane #+# #+# */
/* Updated: 2024/02/12 12:03:16 by aheinane ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void free_stack(t_node **stack)
{
t_node *temp;
t_node *current;
current = *stack;
if (!stack)
return ;
while (current)
{
temp = current->link;
free(current);
current = temp;
}
*stack = NULL;
}
void free_array(char **array)
{
int i;
i = 0;
while (array[i])
{
if (array[i] != NULL)
{
free(array[i]);
array[i] = NULL;
i++;
}
}
if (array != NULL)
{
free(array);
array = NULL;
}
}