please tell me what's wrong in my code.

HERE IS A PROGRAM TO INSERT AN ELEMENT IN BINARY TREE

tree *create_new_node(int n)
{
np=new tree;
np->data=n;
np->left=NULL;
np->right=NULL;

return np;
}

tree *insert(int item,tree *t)
{
np=create_new_node(item);

if(t==NULL)
{
t=np;
return t;
}

else
{
if(item < t->data)
return insert(item,t->left);
else
return insert(item,t->right);
}
}

in this code can u please tell me HOW?? the return statement works and what's wrong with it.
The parameter t passed to insert is passed by value. So when you make changes to it within the function, they're not reflected outside of the function. You need to pass the tree* by reference some how.
Topic archived. No new replies allowed.