Homework/HW07/bin-trees-B.cc
void destroyABinaryTree(nodePtr &rootp)
{
    //Only attempt to delete the node and subtree if the node exists.
    if (rootp)
    {
        //Delete the tree from the bottom up.  This prevents memory leaks from deleting a low level
        //node and losing access to its subtree.
        destroyABinaryTree(rootp->left);
        destroyABinaryTree(rootp->right);

        //Once the recursive calls are done, actually delete the node referenced by rootp.
        delete rootp;
        //Set rootp to NULL, which, because it's a reference parameter, will set the left or right
        //data member to NULL as well.
        rootp = NULL;
    }
}
/****************  D E S T R O Y   A   B I N A R Y   T R E E  ***************

The following function deallocates all the nodes in the binary tree
pointed to by "rootp", and it makes the tree empty (i.e., it changes to
NULL the value of the pointer passed to it).  The function is recursive.
The function documentation and heading were written by W. Knight.  */
D E S T R O Y   A   B I N A R Y   T R E E
The following function deallocates all the nodes in the binary tree
pointed to by "rootp", and it makes the tree empty .  The function is recursive.
The function documentation and heading were written by W. Knight.
D E S T R O Y A B I N A R Y T R E E The following function deallocates all the nodes in the binary tree pointed to by " rootp " and it makes the tree empty . The function is recursive . The function documentation and heading were written by W . Knight .
void destroyABinaryTree(nodePtr &rootp)
{
    if (rootp)
    {
        destroyABinaryTree(rootp->left);
        destroyABinaryTree(rootp->right);
        delete rootp;
        rootp = NULL;
    }
}
void destroyABinaryTree ( nodePtr & rootp ) { if ( rootp ) { destroyABinaryTree ( rootp -> left ) ; destroyABinaryTree ( rootp -> right ) ; delete rootp ; rootp = NULL ; } }
D E S T R O Y   A   B I N A R Y   T R E E
The following function deallocates all the nodes in the binary tree
pointed to by "rootp", and it makes the tree empty (i.e., it changes to
NULL the value of the pointer passed to it).
D E S T R O Y A B I N A R Y T R E E The following function deallocates all the nodes in the binary tree pointed to by " rootp " and it makes the tree empty ( i . e . it changes to NULL the value of the pointer passed to it ) .
//Only attempt to delete the node and subtree if the node exists. //Delete the tree from the bottom up.  This prevents memory leaks from deleting a low level //node and losing access to its subtree. //Once the recursive calls are done, actually delete the node referenced by rootp. //Set rootp to NULL, which, because it's a reference parameter, will set the left or right //data member to NULL as well.