-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory_mng.c
48 lines (45 loc) · 1.47 KB
/
memory_mng.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* memory_mng.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dfurneau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/15 20:46:38 by dfurneau #+# #+# */
/* Updated: 2021/12/10 05:15:24 by dfurneau ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/push_swap.h"
/**
* Malloc and initialize the stacks A and B
* Zero based stack
**/
void init_stack(int ac, t_stack *a, t_stack *b)
{
a->stack = (int *)malloc(sizeof(int) * ac - 1);
b->stack = (int *)malloc(sizeof(int) * ac - 1);
if (!a->stack && !b->stack)
error(NULL, NULL);
a->top = (ac - 1) - 1;
a->len = (ac - 1);
b->top = -1;
b->len = 0;
a->name = 'a';
b->name = 'b';
}
/**
* Free memory allocations of both stack A and B
**/
void free_stack(t_stack *a, t_stack *b)
{
if (a)
{
free(a->stack);
a->stack = NULL;
}
if (b)
{
free(b->stack);
b->stack = NULL;
}
}