1

Iterative PostOrder traversal deletes the Whole tree, in Scala we have :

override def clone():BinarySearchTree=
{
  return new BinarySearchTree(root.clone())
}

Then we copy the whole tree by using :

def postorder(tnode:TreeNode) 
{    
   var tcnode=tnode.clone
}

now tcnode have the copy of the whole tree. But I want to do the same in python I tried using :

import copy
def postOrder(self, tnode):
    tcnode = copy.copy(tnode)

but it's not working.

1 Answer 1

1

use tcnode=copy.deepcopy(tnode) because deepcopy doesn't change the original tree but in your case you are using Shallow copy in this case it will change the original tree, for more information on deepcopyDifference between DeepCopy and Shallow copy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.