t_btree *ft_btreemap_suffix(t_btree *root, t_btree *(*f)(const t_data *)) { t_data tmp; t_btree *node; t_btree *left; t_btree *right; if (!root || !f) return (NULL); if (root->left) left = ft_btreemap_infix(root->left, f); if (root->right) right = ft_btreemap_infix(root->right, f); tmp.data = root->content; tmp.data_size = root->content_size; if (!(node = (*f)(&tmp))) { ft_btreedel(&left, &del); ft_btreedel(&right, &del); return (NULL); } if (root->left && (left->parent = node)) node->left = left; if (root->right && (right->parent = node)) node->right = right; return (node); }
void ft_btreedel(t_btree *tree) { if (tree) { ft_btreedel(tree->left); ft_btreedel(tree->right); tree->content_size = 0; tree->left = NULL; tree->right = NULL; free(tree->content); free(tree); tree = NULL; } }