data_structures
src
data_structures
rbt
rbt_delete.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* rbt_delete.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2020/07/18 00:24:47 by unite #+# #+# */
10
/* Updated: 2020/07/18 13:47:49 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
rbt.h
"
15
16
void
rbt_delete_node(
t_rbt
*rbt,
t_rbt_node
*node)
17
{
18
if
(node == NULL)
19
return ;
20
rbt->
val_type
->
del
(node->
val
);
21
rbt->
key_type
->
del
(node->
key
);
22
free(node);
23
}
24
25
void
rbt_delete_recur(
t_rbt
*rbt,
t_rbt_node
*node)
26
{
27
if
(node == NULL)
28
return ;
29
rbt_delete_recur(rbt, node->
left
);
30
rbt_delete_recur(rbt, node->
right
);
31
rbt_delete_node(rbt, node);
32
}
33
34
void
rbt_delete
(
t_rbt
*rbt)
35
{
36
if
(rbt == NULL)
37
return ;
38
rbt_delete_recur(rbt, rbt->
root
);
39
free(rbt);
40
}
rbt_delete
void rbt_delete(t_rbt *rbt)
Deletes this tree and free all its items and the associated data.
Definition:
rbt_delete.c:34
s_rbt
A left-leaning red-black binary search tree.
Definition:
rbt.h:72
s_rbt_node::right
struct s_rbt_node * right
The right child.
Definition:
rbt.h:56
s_rbt_node::left
struct s_rbt_node * left
The left child.
Definition:
rbt.h:55
s_rbt::val_type
const t_type * val_type
The type of values in the ree.
Definition:
rbt.h:76
s_rbt_node::key
void * key
The key.
Definition:
rbt.h:53
s_type::del
void(* del)(void *)
A function pointer used to free the memory taken by the data type.
Definition:
types.h:51
s_rbt::key_type
const t_type * key_type
The type of keys in the tree.
Definition:
rbt.h:75
rbt.h
s_rbt_node
A node in a red-black tree.
Definition:
rbt.h:51
s_rbt::root
t_rbt_node * root
The root of the tree.
Definition:
rbt.h:74
s_rbt_node::val
void * val
The value.
Definition:
rbt.h:54
Generated by
1.8.16