cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Copy constructor.
Copy constructor.
Dec 19, 2015 at 8:29am UTC
The suffocated
(40)
Here is a way to copy a binary tree in a recursive way. It's pretty fine. But I'm assumed to write an iterative one as well. Please, someone tell me how can it be done.
P.S. It's quite urgent. Thanks in advance.
template<typename T> NODE<T>* BST<T>::copyTree(NODE<T>* root)
{
NODE<T>* copyNode = NULL;
if (root)
{
copyNode = new NODE<T>();
copyNode->data = root->data;
copyNode->left = copyTree(root->left);
copyNode->right = copyTree(root->right);
}
return copyNode;
}
Dec 19, 2015 at 10:11am UTC
kbw
(9488)
That code looks ok. Doesn't it work?
Dec 19, 2015 at 11:21am UTC
The suffocated
(40)
It does. But I have an assignment to implement it in an iterative way as well, and I have no idea how to do that.
Topic archived. No new replies allowed.