Esempio n. 1
0
void		ft_treeadd(t_tree **a, void *content, int(*sort)())
{
	if (*a == NULL)
		*a = ft_treenew(content);
	else if (sort(content, (*a)->content) < 0)
		ft_treeadd(&((*a)->left), content, sort);
	else
		ft_treeadd(&((*a)->right), content, sort);
}
Esempio n. 2
0
void	ft_treeins(t_tree *tree, void *data, int (*cmp)(void*, void*))
{
	int		outcome;
	t_tree	*next;

	if (tree != NULL && cmp != NULL)
		while (tree->left != NULL || tree->right != NULL)
		{
			if ((outcome = cmp(data, tree->data)) <= 0)
				next = tree->left;
			else
				next = tree->right;
			if (next != NULL)
				tree = next;
			else
			{
				if (outcome <= 0)
					tree->right = ft_treenew(data);
				else
					tree->left = ft_treenew(data);
				return ;
			}
		}
}