Reputation:
I am working with a binary search tree. Here I'm writing a function to delete an item from the tree. In the following code:
if(root = NULL)//if there is nothing in the tree
{
cout<<"the Tree is empty"<<endl;//ouput to the screen
return;//exit the function
}
bool isFound = false;//tells us if the item is found
Node* tmp = new Node();//declare a temp pointer
Node* tmp2 = new Node();;//declare a temp pointer
tmp* = *root;//assign the pointer to something
It is calling the copy constructor, but as I have it right now I'm just copying the values like this:
Node& Node::operator= (const Node& node)
{
data = node.data;
left = node.left;
right = node.right;
return *this;
}
Upvotes: 0
Views: 89
Reputation: 29724
if(root = NULL)
change it to
if(root == NULL)
it is also wrong:
tmp* = *root;//assign the pointer to something
Upvotes: 0
Reputation: 258618
You're assigning pointers, to assign the objects you need
*tmp = *root;
tmp
and root
are of type Node*
; *tmp
and *root
are of type Node
.
Upvotes: 1