-
Notifications
You must be signed in to change notification settings - Fork 2
/
ft_avlnew.c
43 lines (40 loc) · 1.42 KB
/
ft_avlnew.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_avlnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rlambert <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/11 14:03:20 by rlambert #+# #+# */
/* Updated: 2015/01/02 15:03:25 by rlambert ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
t_avl *ft_avlnew(int key, void *content, size_t content_size)
{
t_avl *avl;
if ((avl = (t_avl*)malloc(sizeof(t_avl))) == NULL)
return (NULL);
avl->key = key;
avl->height = 1;
if (content != NULL)
{
avl->content = malloc(content_size);
if (avl->content == NULL)
{
free(avl);
return (NULL);
}
ft_memcpy(avl->content, content, content_size);
avl->content_size = content_size;
}
else
{
avl->content = NULL;
avl->content_size = 0;
}
avl->left = NULL;
avl->right = NULL;
return (avl);
}