forked from josanri/Libft_extended
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_btree_search_item.c
33 lines (31 loc) · 1.43 KB
/
ft_btree_search_item.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_btree_search_item.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: josesanc <josesanc@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/18 19:41:48 by josesanc #+# #+# */
/* Updated: 2023/02/18 19:41:48 by josesanc ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief Searches an item and returns it if found
*
* @param root
* @param data_ref
* @param cmpf
* @return void*
*/
void *ft_btree_search_item(t_btree *root,
void *data_ref, int (*cmpf)(void *, void *))
{
if (ft_btree_search_item(root->left, data_ref, cmpf) != NULL)
return (ft_btree_search_item(root->left, data_ref, cmpf));
if (cmpf(root->item, data_ref) == 0)
return (root->item);
if (ft_btree_search_item(root->right, data_ref, cmpf) != NULL)
return (ft_btree_search_item(root->right, data_ref, cmpf));
return (NULL);
}