In your
insert
function the data member is not assigned when the
p_tree
parameter is
NULL
:
if(p_tree=NULL)
{
node*p_new_tree=new node;
p_new_tree->p_left=NULL;
p_new_tree->p_right=NULL;
p_new_tree->data=data;
return p_new_tree;
}
In the other cases no value is returned by the
insert
function. This should raise a compiler warning.
In your first call you are passing an unitialised parameter which should raise a compiler warning too:
node*p_temp;
insert(p_temp,4);
When
p_temp
is not
NULL
here, the program crashes (access violation). When it is
NULL
, a new node is allocated but nowhere stored to be later used (return value not used).
Overall you should rethink your implementation. It would not work this way.