Esempio n. 1
0
int containsBSTree(struct BSTree *tree, TYPE val)
{
        assert(val != 0);
	struct BSTree *tmp = newBSTree();
	assert(tmp != 0);
	
	if(compare(val, tree->root->val) == 0)
	{
	    clearBSTree(tmp);
	    deleteBSTree(tmp);
       	    return 1;
	}
	else if(compare(val, tree->root->val) == -1)
	{
	    tmp->root = tree->root->left;
	    
	}
	else if(compare(val, tree->root->val) == 1)
	{
	    tmp->root = tree->root->right;
	    
	}	
	if(tmp->root == NULL)
	{
	  clearBSTree(tmp);
	  deleteBSTree(tmp);
	  return 0;
	}

	return containsBSTree(tmp, val);
}
Esempio n. 2
0
/*
 function to deallocate a dynamically allocated binary search tree
 param: tree   the binary search tree
 pre: tree != null;
 post: all nodes and the tree structure itself are deallocated.
 */
void deleteBSTree(struct BSTree *tree)
{
	assert (tree != 0);

	clearBSTree(tree);
	free(tree);
}
Esempio n. 3
0
/*
 function to deallocate a dynamically allocated binary search tree
 param: tree   the binary search tree
 pre: tree != null;
 post: all nodes and the tree structure itself are deallocated.
 */
void deleteBSTree(struct BSTree *tree)
{
	clearBSTree(tree);
	free(tree);
}