Post-order traversal to realize the algorithm of deleting the tree java

Delete tree

In order to delete the tree, it is necessary to traverse all the nodes of the tree, and then delete them one by one. Considering that the pre-order traversal, the middle-order traversal, and the layer-order traversal require additional space overhead, therefore, the post-order traversal is the most suitable

void deleteBinaryTreeNode(BinaryTreeNode root){
    
    
  if(root == null)
   return;
  deleteBinaryTreeNode(root.getLeft());
  deleteBinaryTreeNode(root.getRight());
  root = null;
}

Guess you like

Origin blog.csdn.net/weixin_37632716/article/details/110402051