temp=newNode;
This assigns a local variable to the pointer, which is discarded when the function returns, losing the new node. Instead, you want to assign it to a pointer inside the tree; maybe something like:
if (temp->data < value) {
if (temp->left) {
temp = temp->left;
} else {
temp->left = newNode;
return;
}
}
as well as for temp->rightif value < temp->data.
also:
if (temp->data == value)
return;
You have a memory leak there; You must delete newNodebefore return.
source
share