-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtree_find.c
More file actions
32 lines (29 loc) · 1.23 KB
/
tree_find.c
File metadata and controls
32 lines (29 loc) · 1.23 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tree_find.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mihykim <mihykim@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/08 01:07:12 by mihykim #+# #+# */
/* Updated: 2020/04/08 22:50:35 by mihykim ### ########.fr */
/* */
/* ************************************************************************** */
#include "tree.h"
t_node *tree_find(t_tree *tree, void *data_ref)
{
t_node *node;
if (tree == NULL || tree->root == NULL)
return (NULL);
node = tree->root;
while (node)
{
if (tree->cmp(node->data, data_ref) == EQUAL)
return (node);
else if (tree->cmp(node->data, data_ref) > 0)
node = node->left;
else
node = node->right;
}
return (NULL);
}