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); }
/* 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); }
/* 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); }