Copy a Binary Tree ★
April 23, 2008
Making a new Binary Tree by creating an exact copy of an existing Binary Tree.
tree_node *copyTree(tree_node *current=NULL, tree_node *otherRoot, tree_node *copiedRoot, int count=0)
{
if (count==0)
{
copiedRoot = otherRoot;
}
if(otherRoot == NULL)
current = NULL;
else
{
current = new tree_node;
current->info = otherRoot->info;
copyTree(current->left, otherRoot->left,copiedRoot, count+1);
copyTree(current->right, otherRoot->right, copiedRoot, count+1);
}
return copiedRoot;
}