xAbhishek.com

Copy a Binary Tree

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;
}

Ping "Copy a Binary Tree": http://xabhishek.com/2008/04/23/copy-a-binary-tree/trackback/

No comments

Write comment








Copyright 2008 Abhishek Nandakumar I Google, Therefore I Am